I have a rule that delays emails that I send. I want a "Send Now" macro that I can assign a button to that will send the email when clicked. The code below disables the rule.
The problem is that messages sent after the rule is disabled go automatically, but messages that were sent before the rule was disabled stay in the mailbox even after the rule is disabled.
The problem is that messages sent after the rule is disabled go automatically, but messages that were sent before the rule was disabled stay in the mailbox even after the rule is disabled.
Code:
Sub SendNow()
Dim olRules As Outlook.Rules
Dim olRule As Outlook.Rule
Set olRules = Application.Session.DefaultStore.GetRules
Set olRule = olRules.Item("DelaySend")
If olRule.Enabled = True Then olRule.Enabled = False
If olRule.Enabled = False Then olRule.Enabled = True
olRules.Save
Set olRules = Nothing
Set olRule = Nothing
'Sub toggleScheduledSendReceive()
' this only works in Outlook 2010 and earlier
' the Line1 code must run BEFORE the Line2 .execute command
' if Line1 comes after the .execute it will randomly return the control's PREVIOUS value rather than the TOGGLED value.
' this because the .execute runs asynchrously.
' Vba starts the .execute, then resumes at line2B
' even though the toggle may or may not have finished.
On Error GoTo err_routine
Dim x
Dim OutlookSendReceiveWasPreviouslyDisabled As Boolean
Line1: OutlookSendReceiveWasPreviouslyDisabled = Application.ActiveExplorer().CommandBars("Standard").Controls("Send/Re&ceive").Controls("Send/Recei&ve Settings").Controls("&Disable Scheduled Send/Receive").State
Line2:
Application.ActiveExplorer().CommandBars("Standard").Controls("Send/Re&ceive").Controls("Send/Recei&ve Settings").Controls("&Disable Scheduled Send/Receive").Execute
Line2b:
If OutlookSendReceiveWasPreviouslyDisabled Then
MsgBox "Send/Receive Enabled."
Else
MsgBox "Send/Receive Disabled"
End If
exit_sub:
Exit Sub
err_routine:
MsgBox Error$
Resume exit_sub
End Sub