我编写了一个简单的宏,用于将所有工作簿保存为单独的 CSV 文件。对于 * D:\MyFolder* 之类的路径,这在我的本地机器(英语语言)上运行良好。
但是,当我在另一台启用了日语的 Windows 机器上尝试相同的宏时,我收到 1004SaveAS
方法错误。
文件路径如D:¥MyFolder¥
以下是导致错误的我的代码:
pathSeparator = Application.PathSeparator
strPath = InputBox("输入现有目录路径,如 d:\someDirectoryName, d:", , , 1000)
SaveToDirectory = strPath & pathSeperator & "csv" & pathSeperator If Dir(strPath & pathSeperator & "csv", vbDirectory) = "" Then fso.CreateFolder SaveToDirectory Else fso.DeleteFolder strPath & pathSeperator & "csv" fso.CreateFolder SaveToDirectory End If For Each WS In ThisWorkbook.Worksheets newName = WS.Name & "-" & Format(Date, "yyyy-mm-dd") & "-" & Format(Time, "hhmmss") WS.Copy ActiveWorkbook.SaveAs SaveToDirectory & newName, xlCSVMSDOS, Local:=True ActiveWorkbook.Close Savechanges:=False Next