VBA Excel file to CSV, keeps CSV filename same as original workbook -
i trying find fast way save xlsx
files csv
files same file-name xlsx
file (just in csv
format). have recorded macro shortcut, issue whenever try new file saves same file-name recorded initial macro (i.e. see below, because have file labelled in code as: 3wdl_1 (2014-08-07)10secdatatable sit.csv
). there need replace 3wdl_1 (2014-08-07)10secdatatable sit.csv
make macro save same file-name actual workbook working with.
so have folder full of xlsx
files , want use shortcut/macro on each xslx
file convert them csv
files have same name original xlsx
file, , saved same folder.
sub xlstocsv() ' ' xlstocsv macro ' ' keyboard shortcut: ctrl+a ' columns("a:a").select range("a41243").activate selection.numberformat = "0.00" activewindow.scrollrow = 41231 activewindow.scrollrow = 41090 activewindow.scrollrow = 39753 activewindow.scrollrow = 30184 activewindow.scrollrow = 26385 activewindow.scrollrow = 13017 activewindow.scrollrow = 10976 activewindow.scrollrow = 8162 activewindow.scrollrow = 4785 activewindow.scrollrow = 4503 activewindow.scrollrow = 774 activewindow.scrollrow = 1 range("a1").select chdir "c:\users\paddy\desktop\new csv files whole cgm date ok!" activeworkbook.saveas filename:= _ "c:\users\paddy\desktop\new csv files whole cgm date ok!\3wdl_1 (2014-08-07)10secdatatable sit.csv" _ , fileformat:=xlcsvmac, createbackup:=false end sub
right now, you've got file-name hard-coded in after "activeworkbook.saveas
" it's saving hard-coded name.
i think you'll want use "activeworkbook.name
" name of current file , concatenate "filename" variable have there (without file extension) new extension. example:
"c:\users\padd\desktop\new csv...ok!\" & left(activeworkbook.name, instr(activeworkbook.name, ".") - 1) & ".csv")
this kind of dirty way it, should serve needs. also, depending on version of excel use, think might need use "thisworkbook
" instead of "activeworkbook
" i'm not sure.
Comments
Post a Comment