I was running a Macro that opens another excel file(.xlsm) and runs a Macro contained in that file.
I restarted my PC and tried to run it. But the code did not work anymore and shown this error:
Run-time error 1004: Cannot run the macro '01.xlsm!ReadCheckBoxes1'.
The macro may not be available in this workbook or all macros may be disabled.
The error comes up when it reaches this line
Call Application.Run(Macro1)
Enable all macros is selected and the trust center has a tick in "Trust access to the VBA project object model"
The full code is below, can you help me please?
Sub FileAnalysis()
Dim File As String
Dim Path As String
Dim Macro1 As String
Dim Macro2 As String
Dim b As Object
Dim Ligne As Integer
Dim wb As Workbook
Set b = ThisWorkbook.Worksheets(7).Buttons(Application.Caller)
With b.TopLeftCell
Ligne = .Row
End With
Application.ScreenUpdating = False
File = ThisWorkbook.Worksheets(7).Cells(Ligne, "B").Text
ThisWorkbook.Worksheets(7).Cells(4, 9) = File 'debug
Path = ActiveWorkbook.Path
ThisWorkbook.Worksheets(7).Cells(4, 10) = Path 'debug
If Dir(Path & "\" & File) = "" Then
MsgBox "File doesn't exist."
Else
Set wb = Workbooks.Open(Path & "\" & File)
ActiveWorkbook.Worksheets(6).Unprotect ("test")
Macro1 = File & "!" & "ReadCheckBoxes1"
Macro2 = File & "!" & "ReadCheckBoxes2"
ThisWorkbook.Worksheets(7).Cells(3, 10) = ActiveWorkbook.Name 'debug
ThisWorkbook.Worksheets(7).Cells(4, 11) = Macro1 'debug
ThisWorkbook.Worksheets(7).Cells(4, 12) = Macro2 'debug
Call Application.Run(Macro1) 'error displayed here
Call Application.Run(Macro2) 'error displayed here if I comment the previous line
wb.Close SaveChanges:=True
ThisWorkbook.Worksheets(7).Cells(Ligne, 4) = "Yes"
ThisWorkbook.Worksheets(7).Cells(4, 13) = "Done"
Application.DisplayFormulaBar = True
ActiveWindow.DisplayWorkbookTabs = True
ActiveWindow.DisplayHeadings = True
ActiveWindow.DisplayGridlines = True
End If
Application.ScreenUpdating = True
If Application.CommandBars("Ribbon").Height <= 100 Then
CommandBars.ExecuteMso "MinimizeRibbon"
End If
Set wb = Nothing
Set b = Nothing
End Sub