Automate macro to run when opening sheet


Posted by Penny Ward on July 12, 2001 3:39 AM

I have a written a macro to retrieve data using Microsoft Query. I need to run this in the middle of the night, so I need to be able to open a spreadsheet and have the macro run automatically without any user intervention. Pls Help.



Posted by gregc on July 12, 2001 8:45 AM

Set up your spreadsheet to start when you want it to by going to start/accesories/systemtools/schedule tasks. In your spreadsheet you can set your macro to run at open. To do that right click on a sheet tab in the workbook and click view code and there are a couple combo boxes near the top, one says general and the other says declarations. Click the one that says general, pick workbook and you should get Open automatically. Put you code at the beginning of the macro and this at the end of the macro
'Your code here

activeWorkbook.Save
Application.Quit


Hope that works for you.