Running macros at scheduled time when pc is locked

2019-06-06 03:02发布

问题:

Background: Windows 7, Office 2010

I currently have 2 macros running by buttons, one macro calculates and extracts data and the other macro selects a specific range and sends an email to a specified email.

May I know how I can get this 2 macros to run at a scheduled time when my pc is locked - i.e. (on 'switch user' screen)?

Thank you and I sincerely appreciate any help I can get!

回答1:

Sub tempo()
    tps = Now + TimeValue("00:01:00") 'your refresh rate
    Application.OnTime tps, "message_ctrl"
End Sub

Sub message_ctrl()
     Call Module1.test  'your macro
     Call tempo 'this just relaunch schedule when test() finished
End Sub

Here exemple to refresh every minutes, but you can define day or anything. You need to start once tempo() or message_ctrl() to start cycle. Maybe at workbook_open. The key here is the Application.OnTime function.