0

Im currently trying to write a "controller" File with a macro, that opens other files and just calls 3 Macros in each file. All these files have the same structure. My Problem is that I can't see the VBA structure, but I do know the Macronames as they are shown to me. But everytime I try to call these macros im getting the following Error Message:

Runtimeerror 1004 The Makro !xxxx can't run. It's maybe not available in this file or all macros have been deactivated.

Macros are activated. If I click the button in that File the macro that gets triggered works perfectly fine.

Any suggestions welcome

Thanks

I've tried everything with wrong filenames with false characters and single commatas. The Opening of the File via Set wb = Workboos.open works perfectly fine, so the file name probably can't be a part of the problem.

braX
  • 11,506
  • 5
  • 20
  • 33
  • 1
    Suggestion: VBA project protection is basically useless, you could just easily [bypass](https://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project) it. – BigBen Nov 22 '22 at 13:57

2 Answers2

1

You need to specify the name of the workbook you are calling the sub from.

Suppose you have these subs in both workbooks 1 & 2:

Public Sub macro1()
    MsgBox "macro1 launched from " & ThisWorkbook.Name
End Sub

Public Sub macro2()
    MsgBox "macro2 launched from " & ThisWorkbook.Name
End Sub

Now you can call the following sub from your controller macro:

Sub launcher()
    Dim wb As Workbook
    
    Set wb = Workbooks.Open("C:\Users\<username>\Desktop\Workbook1.xlsm")
    
    Application.Run wb.Name & "!" & "macro1" 'the distant macro which you know the name
End Sub

Works perfectly

0

Answer to the riddle: Even tho I thought that I checked the File Name with 'Filename.xlsm', the problem resolved when I removed all dashes from the Filenames!