为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

我想每半小时在Outlook(VBA)中运行一个特定的代码。而且,在代码运行时,Outlook用户也不应受到打扰。它应仅在后端运行。有一个名为的事件Application_Reminder。它在Outlook中每次出现提醒时运行。但这仍然涉及用户交互。我想要一个完整的后端程序。
查看完整描述

3 回答

?
慕运维8079593

TA贡献1876条经验 获得超5个赞

对于Win64,我需要将其更改为:


Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong, ByVal uElapse As LongLong, ByVal lpTimerfunc As LongLong) As LongLong

Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong) As LongLong


Public TimerID As LongLong 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is running


Public Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)

  MsgBox "The TriggerTimer function has been automatically called!"

End Sub



Public Sub DeactivateTimer()

Dim lSuccess As LongLong

  lSuccess = KillTimer(0, TimerID)

  If lSuccess = 0 Then

    MsgBox "The timer failed to deactivate."

  Else

    TimerID = 0

  End If

End Sub


Public Sub ActivateTimer(ByVal nMinutes As Long)

  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes

  If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer

  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)

  If TimerID = 0 Then

    MsgBox "The timer failed to activate."

  End If

End Sub


查看完整回答
反对 回复 2019-10-30
?
12345678_0001

TA贡献1802条经验 获得超5个赞

更正64位的上限答案:


Declare PtrSafe Function SetTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong, ByVal uElapse As LongLong, ByVal lpTimerfunc As LongLong) As LongLong

Declare PtrSafe Function KillTimer Lib "user32" (ByVal hwnd As LongLong, ByVal nIDEvent As LongLong) As LongLong


Public TimerID As LongLong 'Need a timer ID to eventually turn off the timer. If the timer ID <> 0 then the timer is running


Public Sub TriggerTimer(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, ByVal Systime As Long)

  MsgBox "The TriggerTimer function has been automatically called!"

End Sub



Public Sub DeactivateTimer()

Dim lSuccess As LongLong              '<~ Corrected here

  lSuccess = KillTimer(0, TimerID)

  If lSuccess = 0 Then

    MsgBox "The timer failed to deactivate."

  Else

    TimerID = 0

  End If

End Sub


Public Sub ActivateTimer(ByVal nMinutes As Long)

  nMinutes = nMinutes * 1000 * 60 'The SetTimer call accepts milliseconds, so convert to minutes

  If TimerID <> 0 Then Call DeactivateTimer 'Check to see if timer is running before call to SetTimer

  TimerID = SetTimer(0, 0, nMinutes, AddressOf TriggerTimer)

  If TimerID = 0 Then

    MsgBox "The timer failed to activate."

  End If

End Sub


查看完整回答
反对 回复 2019-10-30

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信