Setting the Account of a created email

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using a script to create a new email and display it for further editing and sending. But I want to pre-select a certain account so I don't have to do that manually. (I use accounts to manage the fact that I have a few different email addresses for different purposes.

I can't see how to do that programatically. Is there a way?
 
I figured this out. Basically you need to drill down through the toolbars
using the CommandBars property of an Inspector displaying the email, to
find and activate the proper element on the Accounts dropdown.

In my case, if I was looking for an account called "DanAccount", I would
use the following code, given that I already had an object for a MailItem,
and I want to set the Account then display it:

Dim inspector as Outlook.Inspector
Dim bars As CommandBars
Dim bar As CommandBar
Dim accountPopup As CommandBarPopup

Set inspector = mailitem.GetInspector
Set bars = inspector.CommandBars
Set bar = bars("Standard")
Set accountPopup = bar.FindControl(msoControlPopup, 31224) ' Accounts
Set bar = accountPopup.CommandBar

Dim control As CommandBarControl
For Each control In bar.controls
If InStr(control.Caption, "DanAccount") Then
control.Execute
Exit For
End If
Next
inspector.Activate
 
Back
Top