views:

47

answers:

2

hi, here's the trick. gotta convert 'bout 300 files from xls to csv, wrote some simple macro to do it, here's the code:

Dim wb As Workbook

For Each wb In Application.Workbooks
wb.Activate

    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
    ActiveWorkbook.SaveAs Filename:= _
        "C:\samplepath\CBM Cennik " & ActiveWorkbook.Name & " 2010-04-02.csv" _
        , FileFormat:=xlCSV, CreateBackup:=False
Next wb

but it doesn't do exactly what i want - saves file "example.xls" as "example.xls 2010-04-02.csv", what i need is "example 2010-04-02.csv"

need support guys ;)

+2  A: 

You could try to remove the extension in your filename.

Instead of ActiveWorkbook.Name use

Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".") - 1)

to remove everything after the last . in the filename (including the .).

Peter Lang
BIG THANKS! :) you've saved the day.
korki
one more problem - it separates columns with "," , but i need ";" as a column separator. any quick solution? i'd be gratefull.
korki
You could try `local:=true` or `local:=false` as parameter to your call to `SaveAs`. If that does not help, please ask another question on StackOverflow - that's how it works. One question, one answer :) And you can/should accept the answer that solved your problem.
Peter Lang
ok, it's my first question here, so thanks for your support ;)! answer marked as helpful.
korki
Thanks, welcome to StackOverflow :) Did the `local` parameter help?
Peter Lang
local:=True worked great! well, already love this place. one more time - thanks, man. now my work is done ;)
korki
+1  A: 

A quick and dirty method is to

Replace(ActiveWorkbook.Name, ".xls", "")
KennyTM
Would not work with `xslx` any more, though :)
Peter Lang