0
votes

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
1
Is the VBA Project protected in the other workbook?SierraOscar
No it isn't, I've just double checked itANG
And the macro runs fine if I open the other file an run itANG
Are there spaces or other "odd" characters in the file name? That often causes problems.ChipsLetten
No. Everything is set to have no spaces, I have also double checked and tried to add the ' in the path. but did not work This is really puzzling me tbfANG

1 Answers

0
votes

I have no idea what happened, but after switching off the laptop (proper switch off) everything started to work again.

Restarting did not work (I tried it 3 times), but switching off and on did make it work again.

A relevant change is that the following warning started to show up before continuing:

"Privacy warning: This document contains macros, ActiveX controls, XML expansion pack information, or Web components. These may include personal information that cannot be removed by the Document Inspector"

If anyone has a clue of what could have happened it would be awesome.

cheers