Run-time error '1004' with a macro

dhosi439

Board Regular
Joined
May 13, 2009
Messages
62
I'm trying to run a macro when the workbook opens. It was working fine, I'm not sure what changed.

Code to run the macro:
Code:
Private Sub Workbook_Open()
Run "PopulateCB"
End Sub
Macro, which works when manually started:
Code:
Private Sub PopulateCB()
For i = 2 To Sheets.Count
If Sheets(i).Visible = xlSheetVisible Then Sheet5.cbSheets.AddItem Sheets(i).Name
Next i
End Sub
and the code for the Combo Box that is populated by the macro:
Code:
Private Sub cbSheets_Change()
On Error Resume Next
Worksheets(cbSheets.Value).Select
Charts(cbSheets.Value).Select
Sheet5.cbSheets.Text = ""
Sheet5.cbSheets.Value = ""
End Sub
Everything works except the Run command for the workbook. We have tried replacing the macro and using Call instead of Run.

Additionally, I have put On Error Resume Next into the Combo box code because of an error that was popping up, which didn't seem to affect the overall performance of the worksheet.

Any help would be great, I've asked several of my coworkers, no one is sure why the call doesn't work. Would it be possible to put the run into the combo box code, for instance when the drop down is clicked it populates, but only does it once?

Thanks for any help.
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Have you tried dropping the Run/Call completely from the Workbook_Open?

Code:
Private Sub Workbook_Open()
    PopulateCB
End Sub

HTH
Russ
 
Upvote 0
Where is the PopulateCB routine located (which module) and why is it Private?
 
Upvote 0
I tried just removing the Run command, however that didn't help.

I also never really had a need for public subs.

What I did to fix my issue was instead of calling the module, I just put my code into the workbook instead.

Thanks for helping.
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,591
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top