Steve Tomalin
Member
- Outlook version
- Outlook 2016 32 bit
- Email Account
- Outlook.com (as MS Exchange)
Hi All,
I've put a macro together from examples I found on the web, which uses the Inspectors.NewInspector event to run code when a new item window opens, whether New, Reply, ReplyAll or Forward. Amongst other things, the macro conditionally changes the value in the 'From' drop-down list, using the MailItem.SendUsingAccount property.
The problem I have is that the setting the SendUsingAccount property seems to work when the macro runs for the very first time, after starting Outlook, but in all subsequent runs of the macro the MailItem.SendUsingAccount line fails to set the value. The MsgBox I included for test purposes appears every time, so I know the macro runs on each occasion.
Could anyone show me what needs to be done with this macro to get it working every time please? Below is a cut down version of the macro, to keep things simple.
Kind regards,
Steve
Dim WithEvents colInsp As Outlook.Inspectors
Private Sub Application_Startup()
Set colInsp = Application.Inspectors
End Sub
Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Dim objMail As Outlook.MailItem
Dim OutApp As Outlook.Application
Set OutApp = Application
If Inspector.CurrentItem.Class = olMail Then
Set objMail = Inspector.CurrentItem
If objMail.Sent = False Then
With objMail
MsgBox "Setting SendAccount Next"
objMail.SendUsingAccount = OutApp.Session.Accounts.Item(5)
End With
End If
End If
Set objMail = Nothing
End Sub
I've put a macro together from examples I found on the web, which uses the Inspectors.NewInspector event to run code when a new item window opens, whether New, Reply, ReplyAll or Forward. Amongst other things, the macro conditionally changes the value in the 'From' drop-down list, using the MailItem.SendUsingAccount property.
The problem I have is that the setting the SendUsingAccount property seems to work when the macro runs for the very first time, after starting Outlook, but in all subsequent runs of the macro the MailItem.SendUsingAccount line fails to set the value. The MsgBox I included for test purposes appears every time, so I know the macro runs on each occasion.
Could anyone show me what needs to be done with this macro to get it working every time please? Below is a cut down version of the macro, to keep things simple.
Kind regards,
Steve
Dim WithEvents colInsp As Outlook.Inspectors
Private Sub Application_Startup()
Set colInsp = Application.Inspectors
End Sub
Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Dim objMail As Outlook.MailItem
Dim OutApp As Outlook.Application
Set OutApp = Application
If Inspector.CurrentItem.Class = olMail Then
Set objMail = Inspector.CurrentItem
If objMail.Sent = False Then
With objMail
MsgBox "Setting SendAccount Next"
objMail.SendUsingAccount = OutApp.Session.Accounts.Item(5)
End With
End If
End If
Set objMail = Nothing
End Sub