I need help setting up macro that runs each time I load Excel 2007. I have tried following a few walkthroughs on the web but they end up not autolaunching the macro.
Answer
You need to have the correct code in the correct place in a specific workbook saved in a specific location to run something when you load Excel.
To do this:
Press Alt+F11 to load the VB Editor
On the left side, you should see the Project Explorer, which is a tree menu of your open workbooks and their coding elements. Press F4 if you do not see this menu.
In the Project Explorer pane, choose the project corresponding to your current workbook and expand out Microsoft Excel Objects under this project. Double-click
ThisWorkbook
to view the code that runs when the workbook is open, closed, deactivated, etc.A macro that runs when the workbook opens needs to look like this:
Private Sub Workbook_Open()
Msgbox "Yes, it worked.", vbinformation + vbokonly, "Macro Launch Successful"
End SubNow, close the VB Editor, but leave Excel open.
Since you want this to run whenever Excel loads, you need to save this workbook as "Personal.xlsm" into the following directory (copy this address to your clipboard then paste it in the Filename field in the Save As dialog):
%appdata%\Microsoft\Excel\XLStart\Personal.xlsmWith the document saved (but still open!), click the
View
tab in Excel's ribbon and click the "Hide" button to hide the workbook. If you don't do this, Personal.xlsm will always appear when you load Excel. Hiding it allows it to be open, but not visible (obv.).Now close Excel and click Yes to save changes to Personal.xlsm.
Reopen Excel to test.
Let me know if this doesn't work.
No comments:
Post a Comment