[R] [OT] VBA to save excel as csv

Eik Vettorazzi E.Vettorazzi at uke.uni-hamburg.de
Mon Jun 15 19:25:37 CEST 2009


Hi Hadley,
in VBA you can do sth. like

Sub save_all_csv()
 oldName = ThisWorkbook.FullName
 curpath = ThisWorkbook.Path
 
  For Each ws In ActiveWorkbook.Worksheets
    ws.SaveAs Filename:=curpath & "\" & ws.Name & ".csv", 
FileFormat:=xlCSV, CreateBackup:=False
 Next
 'bring old file back
 Workbooks.Open Filename:=oldName
 ThisWorkbook.Close savechanges:=False
End Sub

My Excel (2000) has no SaveCopyAs - method for other file formats than 
xls, so I'm using .SaveAs, which saves the file and replaces the current 
worksheet with the saved one - thats why the code for bringing back the 
starting file
hth.


Hadley Wickham schrieb:
> Hi all,
>
> This is a little off-topic, but it is on the general topic of getting
> data in R.  I'm looking for a excel macro / vba script that will
> export all spreadsheets in a directory (with one file per tab) into
> csv.  Does anyone have anything like this?
>
> Thanks,
>
> Hadley
>
>   

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790




More information about the R-help mailing list