我正在尝试将当前名为Gaf的Excel保存为CSV格式。
ActiveWorkbook.SaveAs Filename:=Workbooks(GAF).Sheets(Sheet1).Range("A2").Value & ".csv", FileFormat:=xlCSV
任何帮助?
或者.......
ActiveWorkbook.SaveAs Filename:="C:\User\Test.CSV" & Test1Str & " " & TestStr & " " & ActiveWorkbook.Name
技术上有效,但不完全是CSV文件......我尝试过输入“.csv”,xlCSV FileFormat:= xlCSV也给我错误。
答案 0 :(得分:0)
这是将Excel工作表转换为csv的众多代码之一。
Sub test()
Dim WB As Workbook, csvWB As Workbook
Dim WS As Worksheet
Dim myPath As String, myFn As String
Dim vDB
myPath = ThisWorkbook.Path & "\"
myFn = myPath & "test.csv"
Set WB = ActiveWorkbook
Set WS = WB.ActiveSheet
vDB = WS.UsedRange
Set csvWB = Workbooks.Add(Template:=True)
With csvWB
Sheets(1).Range("a1").Resize(UBound(vDB, 1), UBound(vDB, 2)) = vDB
.SaveAs myFn, xlCSV
.Close (0)
End With
Set csvWB = Nothing
End Sub