当您收到“错误”时,有用的“错误消息”会提示您问题所在。通过阅读此消息并对其采取行动,您可以逐步调试您的代码。
Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat = 52
' Variable not defined ^
在 VBA 中指定参数的方法是使用:=
,而不是=
。让我们纠正它并再次运行它......
Activeworkbooks.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
' ^ Variable not defined
它被称为ActiveWorkbook
,不是Activeworkbooks
。让我们纠正它并再次运行它......
ActiveWorkbook.SaveAs "c:\Allfiles(1):&:Allfiles (count).xlsm", FileFormat:=52
' ^ The file could not be accessed.
我不能声称确切知道您正在运行什么操作系统,但鉴于C:\
,我会假设一些 Windows 风格。您可能知道这:
是 Windows 路径中的非法字符?
无论如何,我不确定您要在哪里保存此文件。我最好的猜测:
ActiveWorkbook.SaveAs "C:\" & Allfiles(1) & Allfiles(UBound(Allfiles)) & ".xlsm", _
FileFormat:=52
至于你的第一行代码,Range (Allfiles(index)).Select
我不知道你想在那里做什么。您可能需要阅读 Excel-VBA 的帮助文件以了解其Range
作用。