ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unattended Macro (https://www.excelbanter.com/excel-programming/274642-re-unattended-macro.html)

Tom Ogilvy

Unattended Macro
 
If you go to the vbe and right click on the ThisWorkbook entry in the
project explorer (under your workbook name), and select view code, you will
get the module where workbook level events can be placed. If you click in
the left dropdown as the top of the module, and select workbook, then in the
right dropdown at the top of the module, you select open, it will enter the
declaration for the workbook_Open event which will run whenever the workbook
is opened and macros are not disabled.

Private Sub Workbook_Open()

End Sub

If you put your code within this procedure or call your code from this
procedure, it will run when the workbook is opened either manually or
through code.

You can use the Schedular app under system tools to provide the command to
open this file using excel at appropriate times.

Your macro can do something like:

Worksheets(Array("Sheets1","Sheets5","Sheets7")).C opy
ActiveWorkbook.SaveAs "C:\myFolder\MyFile" & format("yyyymmdd") & ".xls"

to save a portion of your workbook to a unique filename - as an example.


--
Regards,
Tom Ogilvy


"buckle" wrote in message news:3f40eef4@nubby2....
Is the following possible?

Run a scheduled task to open an Excel spreadsheet and run a macro
automatically, then close the spreadsheet and return to the desktop. Seems
simple enough but I can't see where to make the macro auto start when the
spreadsheet opens. Also is it possible to save part of the spreadsheet to

a
unique file name (in the macro)?

Thanks





buckle

Unattended Macro
 
Thanks Tom. It's so easy when someone else does all the hard work!

Cheers




All times are GMT +1. The time now is 11:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com