Home » excel » How to fix 1004 error with macros in Excel VBA?

How to fix 1004 error with macros in Excel VBA?

Posted by: admin May 14, 2020 Leave a comment

Questions:

We have the main file on our server which contains all the VBA code and macros. We have local files in a bunch of machines in the company on which the macros from the main file are being called to start a procedure. Not sure why but recently they stopped working properly. Does anyone have any ideas on how to fix this?

I checked the macros settings and they are enabled on all computers so this is not the case. It was working fine last week but it all started in this week.

Private Sub CommandButton_CreatePanelTest_Click()
    Application.Run ("'Y:\XXX\Main.xlsm'!CreatePanelMacro")
    IgnoreReadOnlyRecommended = False
    Workbooks(Dir("Y:\XXX\Main.xlsm")).Close Savechanges:=False
End Sub
How to&Answers:

Open the workbook before you run a macro in it.

Dim Wb As Workbook
Set Wb = Workbooks.Open("Y:\XXX\Main.xlsm")
Application.Run "'Main.xlsm'!CreatePanelMacro"
IgnoreReadOnlyRecommended = False
Wb.Close SaveChanges:=False