Outlook VBA-每半小时运行一次代码

我想每半小时在Outlook(VBA)中运行一个特定的代码。


而且,在代码运行时,Outlook用户也不应受到打扰。它应仅在后端运行。


有一个名为的事件Application_Reminder。它在Outlook中每次出现提醒时运行。但这仍然涉及用户交互。我想要一个完整的后端程序。


汪汪一只猫
浏览 996回答 3
3回答

慕运维8079593

对于Win64,我需要将其更改为:Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong, ByVal uElapse As LongLong, ByVal lpTimerfunc As LongLong) As LongLongDeclare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong) As LongLongPublic TimerID As LongLong 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is runningPublic Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)&nbsp; MsgBox "The TriggerTimer function has been automatically called!"End SubPublic Sub DeactivateTimer()Dim lSuccess As LongLong&nbsp; lSuccess = KillTimer(0, TimerID)&nbsp; If lSuccess = 0 Then&nbsp; &nbsp; MsgBox "The timer failed to deactivate."&nbsp; Else&nbsp; &nbsp; TimerID = 0&nbsp; End IfEnd SubPublic Sub ActivateTimer(ByVal nMinutes As Long)&nbsp; nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes&nbsp; If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer&nbsp; TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)&nbsp; If TimerID = 0 Then&nbsp; &nbsp; MsgBox "The timer failed to activate."&nbsp; End IfEnd Sub

12345678_0001

更正64位的上限答案:Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong, ByVal uElapse As LongLong, ByVal lpTimerfunc As LongLong) As LongLongDeclare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong) As LongLongPublic TimerID As LongLong 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is runningPublic Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)&nbsp; MsgBox "The TriggerTimer function has been automatically called!"End SubPublic Sub DeactivateTimer()Dim lSuccess As LongLong&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<~ Corrected here&nbsp; lSuccess = KillTimer(0, TimerID)&nbsp; If lSuccess = 0 Then&nbsp; &nbsp; MsgBox "The timer failed to deactivate."&nbsp; Else&nbsp; &nbsp; TimerID = 0&nbsp; End IfEnd SubPublic Sub ActivateTimer(ByVal nMinutes As Long)&nbsp; nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes&nbsp; If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer&nbsp; TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)&nbsp; If TimerID = 0 Then&nbsp; &nbsp; MsgBox "The timer failed to activate."&nbsp; End IfEnd Sub
打开App,查看更多内容
随时随地看视频慕课网APP