步骤1:单击开发工具选项卡下的“Visual Basic”命令,或者按“ALT + F11”快捷方式。
步骤2:然后将出现“Visual Basic编辑器”窗口。
步骤3:单击“插入” – >“模块”以创建新模块。
步骤4:将以下VBA代码粘贴到代码窗口中。然后单击“保存”按钮。
Public Sub SaveWorksheetsAsCsv()
Dim WS As Excel.Worksheet
Dim SaveToDirectory As String
Dim CurrentWorkbook As String
Dim CurrentFormat As Long
CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
' Store current details for the workbook
SaveToDirectory = "D:\tmp\"
//可根据需要更改存储路径
For Each WS In ThisWorkbook.Worksheets
WS.SaveAs SaveToDirectory & WS.Name, xlCSV
Next
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Filename:=CurrentWorkbook, FileFormat:=CurrentFormat
Application.DisplayAlerts = True
' Temporarily turn alerts off to prevent the user being prompted
' about overwriting the original file.
End Sub
步骤5:返回当前工作表,然后运行上面的excel宏。位置选择当前excel文件(····.xlsx) ,点击执行按钮。
步骤6:您将看到所有工作表已转换为指定目录中的单个CSV文件
链接:https://www.office26.com/excel/how-to-save-or-export-each-worksheet-as-.html