简体   繁体   中英

vba: save workbook as csv file

I am trying to save a workbook specified using a workbook object as file format csv but having a few problems. In the below code, I get an error after the save-as line, saying the .csv file is read-only:

Sub Button1_Click()
    Dim c As Workbook
    Set c = Application.Workbooks.Open(Filename:="C:\Testing\testbook.xlsx", IgnoreReadOnlyRecommended:=True)
    Call sSaveWorkbookAsCSV(c, "C:\Testing")
End Sub

Public Sub WBookToCSV(wkbktosv As Workbook, strOutputFilePath As String)

    Application.DisplayAlerts = False
    Call wkbktosv.SaveAs(strOutputFilePath, xlCSV, CreateBackup:=False)
    Application.DisplayAlerts = True
    Call wkbktosv.Close(SaveChanges:=False)

End Sub

您应该将其更改为:sSaveWorkbookAsCSV(c,“ C:\\ Testing.csv”)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM