Save As ...
)时,我必须手动执行12次(分别针对每个工作表)。有没有办法不手动执行或一步手动执行此操作?
答案 0 :(得分:3)
我提供了来自vba的vbs代码的Export each sheet to a separate csv file版本
它将单个工作表保存到与主机工作簿(ActiveWorkbook
)相同的路径,并使用从主机工作簿中使用的每个工作表选项卡的名称作为文件名。
Sub SaveAsCSV()
Dim objWB As Workbook
Dim objws As Worksheet
Set objWB = ActiveWorkbook
If Len(objWB.Path) = 0 Then
MsgBox ActiveWorkbook.Name & " is not saved. Please save file then re-run this code", vbCritical
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
For Each objws In objWB.Sheets
objws.Copy
ActiveWorkbook.SaveAs objWB.Path & "\" & objws.Name & ".csv", xlCSV
ActiveWorkbook.Close False
Next
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub