Excel_app_v1.xlsm
所示,并且在该选项卡下创建了一个按钮来连接宏。因此,当我点击此按钮时,宏会执行一些表格导入应用程序。第一个奇怪的事情是,我仅为此Excel文件创建了此选项卡和按钮,但是即使原始Excel文件
Excel_app_v1.xlsm
未打开,选项卡和按钮也会出现在所有其他Excel文件中。第二个问题是,我使用“另存为”选项创建了我以前的Excel文件的第二个版本。因此,新的Excel文件就像
Excel_app_v2.xlsm
一样。当我单击选项卡下的按钮时,它会打开第一个Excel文件Excel_app_v1.xlsm
,即使它没有打开。我删除了第一个Excel文件,但是然后出现了错误,如“在路径上找不到Excel_app_v1.xlsm
”。显然,自定义选项卡下的宏按钮链接到第一个Excel文件,但我找不到更改此内容的菜单选项。我在vba代码中的所有
sheet
表达式之前添加了ThisWorkbook
,但无法解决问题。单击按钮仍然尝试打开旧的Excel文件。以下是VBA代码。按钮链接到
Sub ImportTable
。首先询问用户是否要继续该过程。在单击按钮后立即打开以前的Excel文件,同时出现消息框。Sub ImportTable()
Application.ScreenUpdating = False
YearMonth = ThisWorkbook.Sheets("tab1").Cells(11, 2).Value
' The Macro button opens the previous Excel file before clicking Yes or No on the message box
answer = MsgBox("Warning! Brings the newest source file. You want to continue?", vbYesNo + vbQuestion, "")
If answer = vbYes Then
RunSASCodeViaBatFile ' Another Sub which runs bat file to run a SAS-code. But it doesn't matter. Because the problem happens before I click on Yes or No.
InsertSASFileIntoExcel
Else ' Nothing happens if clicking No on the Message Box
End If
End Sub
Sub
过程,当您单击按钮时,宏将进入该过程。 - user3714330