Reputation: 4701
I've written a Macro in Outlook 2013 where I need to retrieve the sender email address as a string
A simple version is
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim oMail As MailItem
Set oMail = Item
Dim sender as String
sender = oMail.SenderEmailAddress
End Sub
The above works great.
I now have added a new email account to Outlook and this is where the issue is.
If I create a new email it uses my [email protected] email address. If I then change the account from which to send the email from (to [email protected]), the SenderEmailAddress within the VBa does not reflect this change... It still shows (in the watch window) as default.mail.com
How can I get Outlook to re-check the sender (as I assume it's caching it some where)?
Upvotes: 2
Views: 3761
Reputation: 66286
All sender related properties are set after the ItemSend
event fires. The earliest you can see sender properties is when the Items.ItemAdd
event fires on the Sent Items folder.
Upvotes: 4
Reputation: 155
Just define your folder in the application:startup
Public Sub Application_Startup()
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderSentbox)
End Sub
Then just change your code above to the itemAdd Event like
Private Sub myFolder_ItemAdd(ByVal item As Object)
Upvotes: 0