Auto running a macro HELP!


Posted by MichaelShreiber on February 08, 2002 8:24 AM

How do I create a shortcut to a spreadsheet so that it will open up and run a particular macro automatically? I don't want the macro to run every time I open Excel, just on a particular spreadsheet. So I don't want to use the startup features. I'm hoping there's a way to pass the info on the command line of the shortcut.

Thanks in advance,

Mike


Posted by jon on February 08, 2002 2:41 PM

not possible.




Posted by Larry Kramer on February 09, 2002 8:39 AM


If I understand you correctly, you should be able to put the name of the macro in the workbook's workbook_open() event. That will cause the macro to run when that workbook is opened. It won't matter how you access the workbook, i.e., by shortcut or via the file/open dialog in Excel.

To get to the event handler, open the VB editor, doubleclick on the "ThisWorkbook" folder in the project explorer pane, select "Workbook" on the
left drop-down at the top of the code pane. The code for Workbook_Open() should appear. Just insert the name of the macro (which will be interpreted as a command to run it).