Macro using the Default Account
An IMAP user created this macro to open a new message form from any message store and use the default account as assigned in Account Settings.
To use: Go to File, Options, Customize Ribbon. Select Macros from Choose Commands from dropdown, add a New Group to Home tab then add the New Mail macro to the new group. Click the Rename button to rename the command and choose a better looking icon.
Public Sub New_Mail() Dim olNS As Outlook.NameSpace Dim oMail As Outlook.MailItem Set olNS = Application.GetNamespace("MAPI") Set oMail = Application.CreateItem(olMailItem) 'use first account in list oMail.SendUsingAccount = olNS.Accounts.Item(1) oMail.Display Set oMail = Nothing Set olNS = Nothing End Sub
See Using VBA Codeif you need help using VBA code.
Macro using a specific account
This macro is assigned to a button on the ribbon - clicking the button selects the account listed in the code. Replace Name_of_Default_Account with your account name (check in Account settings for the account name). You can create a macro for each account (change the Public Sub name) if desired.
Go to File, Options, Customize Ribbon. Select Macros from Choose Commands from dropdown, add a New Group to Home tab then add the New Mail macro to the new group. Click the Rename button to rename the command and choose a better looking icon.
If you need help customizing the ribbon, see Customizing the Quick Access Toolbar (QAT)
Public Sub New_Mail() Dim oAccount As Outlook.Account Dim oMail As Outlook.MailItem For Each oAccount In Application.Session.Accounts If oAccount = "Name_of_Default_Account" Then Set oMail = Application.CreateItem(olMailItem) oMail.SendUsingAccount = oAccount oMail.Display End If Next End Sub
Note: this macro also works with Outlook 2007 (possibly older versions).
Set the From address on a message
Similar to the previous macro, except it uses a different From address, not a different email account in your profile. Because the message is sent from the default email account, the default account needs Send As permission for the address.
If the account does not have Send as permission, the message will be sent from the default account on behalf of the address or will bounce if using Exchange server. If you are using a SMTP server the message may be sent from the default account.
Use this code to fill in the From field with an address you have permission to send messages From.
Public Sub CreateNewMessageFrom() Dim objMsg As MailItem Set objMsg = Application.CreateItem(olMailItem) With objMsg .SentOnBehalfOfName = "firstname.lastname@example.org" .BCC = "email@example.com" .Display End With Set objMsg = Nothing End Sub
Send a meeting request using a specific account
Use this macro to send meeting requests using a specific account, irregardless of which data file you are viewing.
Public Sub NewMeeting() Dim oAccount As Outlook.Account Dim oMeeting As Outlook.AppointmentItem For Each oAccount In Application.Session.Accounts If oAccount = "account@displayname" Then Set oMeeting = Application.CreateItem(olAppointmentItem) oMeeting.MeetingStatus = Outlook.OlMeetingStatus.olMeeting oMeeting.SendUsingAccount = oAccount oMeeting.Display End If Next End Sub
To use VBA code, press Alt+11 to open the VBA Editor. Locate ThisOutlookSession and paste the code into the editor.
Press F5 or the Run button to test the macro. (It's highly recommended you make a backup of the folder or message store before running macros.)
You'll also need to change macros security or use selfcert.exe to sign your macros. Access the dialog to change the security level from Tools, Macros, Security. (This is at File tab, Options, Trust Center, Macro Security in Outlook 2010). Set it on "always ask". Do not choose the Low option (run all, never ask). Some security software will set it to High and your macros will not run.
To run a macro later, press Alt+F8 to open the macro dialog, then select the macro and choose Run. Or add a button for the macro to your toolbar or add it to the QAT in Outlook 2010.