I created a custom ribbon tab on my Excel like Excel_app_v1.xlsm
, and a button under this ribbon tab is connected to a macro. So when I click this button, the macro does some table importing applications.
The first strange thing is that I created this ribbon tab and the button for only this Excel file, but the ribbon tab and the button appear in all other Excel files, even if the original Excel file Excel_app_v1.xlsm
is not open.
The second problem is that I created a second version of my previous Excel file with "Save-as" option. So the new Excel file is like Excel_app_v2.xlsm
. When I click the button under the ribbon tab, it opens the first Excel file Excel_app_v1.xlsm
, even if it is not open. I deleted the first Excel file, but then I got an error like "Couldn't find the Excel_app_v1.xlsm
on the path".
So obviously the macro button under the customized ribbon tab is linked to the first Excel file, but I couldn't find the menu option to change this. I added ThisWorkbook
before all the sheet
expressions in the vba code, but it didn't solve the problem. The button-click is still trying to open the old excel file.
The VBA code is below. The button is linked to the Sub ImportTable
. Firstly it asks the user if the user wants to continue with the process. It opens the previous Excel file right after clicking on the button, at the same time as the Message Box appears.
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