FlorisMK
asked on
Set Email Account for New Message From VBA
For convenience, I want to create a button in Outlook that creates a MailItem and sets some properties. Specifically, I want to have a button for creating a private email message. The code should:
1 - Create a new message.
2 - Set the BodyFormat to plain text.
3 - Set the email account to my private account.
4 - Display the new message with the focus set to the Body textbox.
Number 3 has me stumped. It seems Outlook doesn't expose the selected email account for a MailItem in its object model. Any ideas? (SendKeys is not an option.)
Public Sub CreatePrivateEmail()
Dim eml As Outlook.MailItem
Set eml = ThisOutlookSession.CreateI tem(olMail Item) ' 1
With eml
.BodyFormat = olFormatPlain ' 2
'Code to set the selected account to my private email account 3, no idea how to do it
.Display ' 4
End With
End Sub
1 - Create a new message.
2 - Set the BodyFormat to plain text.
3 - Set the email account to my private account.
4 - Display the new message with the focus set to the Body textbox.
Number 3 has me stumped. It seems Outlook doesn't expose the selected email account for a MailItem in its object model. Any ideas? (SendKeys is not an option.)
Public Sub CreatePrivateEmail()
Dim eml As Outlook.MailItem
Set eml = ThisOutlookSession.CreateI
With eml
.BodyFormat = olFormatPlain ' 2
'Code to set the selected account to my private email account 3, no idea how to do it
.Display ' 4
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points.
I haven't tried this, but this web page:(http://vbaadventures.blogspot.com/2008/03/automatic-email-account-assignment-in.html) seems to suggest that you can change the account using something called the "Redemption COM Library".
ASKER
Brilliant, anywaste! That's excellent news! I've posted a request on CS to award you points. However did you find this question?
ASKER
I'm posting points for you in this topic; easier than reopening, CS tells me :-)