automatic launching of macro at startup

dan_m

New Member
Joined
Dec 29, 2006
Messages
46
I would like to have a macro launched everytime I open my
workbook, is there a simple way of doing this? Similarily,
I would like a macro ran automatically everytime I
close the wookbook. Any help would be appreciated- thx.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Dan

Take a look at the Workbook's open event.

It can be accessed by right clicking the small XL icon next to File on the main toolbar and selecting View Code.

That should open up the VBA editor in the ThisWorkbook module.

If you select Workbook from the left dropdown you should see this code stub.
Code:
Private Sub Workbook_Open()
     MyMacro
End Sub
This is where any code to be executed when the workbook is opened should go.

There is a similar BeforeClose event.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    MyMacro
End Sub
 
Upvote 0
follow up question

I have just changed to Excel 2007. When I try to open the file it gives me this: "Cannot find 'AutoOpen Stub Data'!$A$1, which has been assigned to run each time masterproposal.xlsm is opened."

I have gone into the VBA editor and under Workbook I have this:

Code:
Private Sub Workbook_Open()

End Sub

I do not see where I can delete what it is asking for....I have Macro's in the workbook, but no longer one I have run when the book opens.

Any help in eliminating this error would be very much appreciated!
 
Upvote 0
To clarify I do not even know what AutoOpen Stub Data is??

I tried to put some code in there and it works, then gives me the Cannot find error.

I see this page in the VBA editor, I changed it from hidden to view, then deleted it....the error just changes to "cannot find ref ref"

Any suggestestions?

Again any help is appreciated....
 
Upvote 0
Has anyone worked on this, I am having the same exact problem.
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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