Started running into this problem again, so went and dug up some code
The following is a step in the right direction, but the mail will not open until the macro actually terminates (so this will keep popping up the messagebox forever, *instead* of opening the email)
Spent 15 minutes looking for a way to trigger custom events from outlook VBA, no luck so far...
Suggestions on fixing would be appreciated, otherwise I'll just post an update when/if I get around to figuring this out.
Dim WithEvents colInsp As Outlook.Inspectors
' Application.Wait doesn't work in outlook 2007, so pull in the windows Sleep function
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliSeconds As Long)
' MessageBox is a non-modular version of MsgBox
Private Declare Function MessageBox _
Lib "User32" Alias "MessageBoxA" _
(ByVal hWnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) _
As Long
Private Sub Application_Startup()
Set colInsp = Application.Inspectors
End Sub
Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Dim objMail As Outlook.MailItem
Dim a As Outlook.MailItem
If Inspector.CurrentItem.Class = olMail Then
Set objMail = Inspector.CurrentItem
'Set a = objMail.Class ' uncomment to trigger an error (for debugging)
Do While objMail.Sent = False
Sleep 3000 ' param is in ms
MessageBox &0, "Unsent message! " & objMail.Subject, "Unsent Mail", vbOKOnly ' this is like MsgBox but doesn't lock up Outlook
Loop
End If
Set objMail = Nothing
End Sub