我当前正在尝试编辑一个打开基本文件[myFile]的宏,并在该基本文件中运行一个单独的宏。通过运行此基本文件,将创建一个全新的工作簿[myFile2]。目的是获取myFile2,调整大小,移动一些工作表等,并创建格式不同的报表[myFile3]。
一切正常,直到我关闭工作簿为止,在该工作簿中出现下标超出范围的错误。
这不是我的原始代码。我正在编辑它,但没有原始作者的访问权限。 “ FALSE”一词在每个工作簿的结束声明中都有,我还想知道这是否与保存更改有关,或者是否与导致问题的其他原因有关?
myPath = "\this\is\a\file\path"
myFile = "base.xlsm"
myPath2 = "\this\is\another\path"
myFile2 = Format(Date, "yymmdd") & "-base_results" & ".xlsm"
myPath3 = "\this\is\a\third\path"
myFile3 = "formatted_base_results" & Format(Date, "mm-dd-yyyy") & ".xlsm"
'open workbook to run macros
Set wkb = Workbooks.Open(Filename:=myPath2 & "\" & myFile2, UpdateLinks:=False)
'run macros in opened workbook
Application.Run ("'" & wkb.Name & "'!" & "MoveSheets")
DoEvents
Application.Run ("'" & wkb.Name & "'!" & "FormatSheets")
DoEvents
Application.Run ("'" & wkb.Name & "'!" & "NewDocument")
DoEvents
'close workbooks
'cant index by full file name
Workbooks(myFile).Close False
Workbooks("DailyBuildPrint - Avg Fare" & Format(Date, "mm-dd-yyyy") & ".xlsm").Close False
Workbooks(myFile2).Close False