Is it possible to run a macro every day at a time?

Is it possible to run a macro every day at a time?



I need to know if it is possible to have a macro executed daily at 7:00 am.



Would this be done through a macro, or through some visual basic component?






For a similar situation I was in, I used Windows task scheduler to open a specific workbook which had the macro I wanted to run, in the Workbook_Open() event.

– Mistella
Sep 11 '18 at 14:48


Workbook_Open()




2 Answers
2



There are a couple ways that I know of to do this, neither of which are perfect.



The first is the Application.OnTime method in VBA (documentation here). This method will schedule another method to be run at a specific time. I haven't thoroughly testing this function, so I don't know if the schedule will be preserved across excel restarts or even workbook closures.


Application.OnTime



Another option is the Windows Task Scheduler(thanks Mistella). You can set up a basic task within the task scheduler to open a specific workbook in excel at a given time at a given interval and have the code you wish to be run within the Workbook's Open event. Within that event you could check the time. If the time is close enough to your designated task scheduler time you could perform the work you needed to do, save the workbook, and close it, all without user interaction.


Open



The issue with the Workbook_Open() event is that if you still need to action on your workbook manually during the day, the macro will launch, which can be source of errors depending on what your macro does.


Workbook_Open()



Alternatively, you can use the Windows Task Scheduler as mentionned above to run a VB Script that will run the macro in your workbook.


Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False 'turn off alerts
xlApp.Application.Visible = False 'keeps Excel hidden
Set xlBook = xlApp.Workbooks.Open("C:MyPathMyWorkbook.xlsm", 0, False)
xlApp.Run "MACRO_NAME"
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing



Just type your script within notepad and save as .vbs (and then have the Windows Task Scheduler to run you .vbs).



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế