我尝试将 excel 电子表格的每个工作表保存到 CSV 文件中。以下脚本完成了这项工作。该行.Parent.Close savechanges:=False
应该关闭创建的工作表,但是当取消注释时,脚本在第一张工作表之后停止。如果我评论该行,所有工作表都会被处理。
Dim newWks As Worksheet
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Copy 'to a new workbook
Set newWks = ActiveSheet
With newWks
.SaveAs Filename:="C:\home\tmp\base\" & wks.Name & ".txt", FileFormat:=xlTextWindows
.Parent.Close savechanges:=False
End With
Next wks
MsgBox "done with: " & ActiveWorkbook.Name