There are two files named file_1.xlsm
and files_2.xlsm
. Both have a Module1.bas
with the same source code.
I've created a customized ribbon with a button that links a macro stored inside Module1.bas
of file_1.xlsm
. I'm trying to use the same button to load macro stored inside ActiveWorkbook
actually, instead of the linked one.
Basically I need to link something like ActiveWorkbook.Module1.bas
instead of file_1.Module1.bas
, but I do not know how to achieve that.
I've tried to link ThisWorkbook but - of course - links to original file.
CodePudding user response:
As I tried explaining in my comment above, you cannot 'link' any module/sub to a Ribbon control calling from another workbook. But, if you really need/want that, at least, for the sake of seeing it working, you can call the respective sub in the next circumstances:
Sub callTheSubInTheActiveWorkbook()
Dim wb As Workbook
Set wb = ActiveWorkbook
If Not wb Is ThisWorkbook Then
If ActiveWorkbook name = "file2.xlsm" then
Application.Run "'" & wb.name & "'!Module1.MySub"
Exit Sub
End If
Else
'run the code here...
End If
End Sub