用于将工作簿中的每个工作表保存为CSV文件的macros

首先让我只是说,我一直在Google上search几个小时,然后尝试每一个在线代码,我可以find,所以不要以为我没有尝试之前询问…

出于某种原因,我发现每一个单一的错误。 我只想要一个macros,将每个.xlsm工作簿保存为.csv文件。 最好我可以让macros创build一个popup窗口,我可以selectCSV文件的目标path。

这将使用Mac版Office 2016。

具体来说,这是我刚刚尝试的一个:

Sub SaveAllSheetsAsCSV2() On Error GoTo Heaven ' each sheet reference Dim Sheet As Worksheet ' path to output to Dim OutputPath As String ' name of each csv Dim OutputFile As String Application.ScreenUpdating = False Application.DisplayAlerts = False Application.EnableEvents = False ' ask the user where to save OutputPath = InputBox("Enter a directory to save to", "Save to directory", Path) If OutputPath <> "" Then ' save for each sheet For Each Sheet In Sheets OutputFile = OutputPath & "/" & Sheet.Name & ".csv" ' make a copy to create a new book with this sheet ' otherwise you will always only get the first sheet Sheet.Copy ' this copy will now become active ActiveWorkbook.SaveAs Filename:=OutputFile, FileFormat:=xlCSV, CreateBackup:=False ActiveWorkbook.Close Next End If Finally: Application.ScreenUpdating = True Application.DisplayAlerts = True Application.EnableEvents = True Exit Sub Heaven: MsgBox "Couldn't save all sheets to CSV." & vbCrLf & _ "Source: " & Err.Source & " " & vbCrLf & _ "Number: " & Err.Number & " " & vbCrLf & _ "Description: " & Err.Description & " " & vbCrLf GoTo Finally End Sub 

我试图改变的一件事是这一行:

 OutputFile = OutputPath & "/" & Sheet.Name & ".csv" 

因为“/”原本是一个“\”,我使用的是Mac,所以我认为这是值得的。 都没有工作。