logo
search
VBA & Macro Problems

How to Fix Excel VBA Sending Email from the Wrong Outlook Account

Huma Ashraf ChHuma Ashraf Ch Oct 9, 2026 869 views

Question details

The user needs their Excel VBA macro to send emails using a specific Outlook account, rather than defaulting to the primary account.

How to Fix Excel VBA Sending Email from the Wrong Outlook Account
Product
Excel, Outlook
Device & OS
not provided
Scenario
Automating email dispatch via Excel VBA when multiple email accounts are configured in the Outlook desktop application.
Observed behavior
The macro sends messages from the default Outlook account. Attempting to fix this by directly assigning an email string to the SendUsingAccount property causes a runtime error, as the property expects an Outlook.Account object.
Before you start

Ensure that the Microsoft Outlook Object Library is referenced in your VBA Editor (Tools > References) and that the target email account is actively configured to send mail in your Outlook application.

Solution 1Recommended

Assign an Outlook.Account Object to SendUsingAccount

Iterate through the available Outlook session accounts to find the matching email address and assign its corresponding object to the mail item.

The SendUsingAccount property does not accept standard text strings. It requires a valid Outlook.Account object. By using a loop to check the SMTP address of each account configured in your Outlook session, you can isolate the correct account object and assign it to your outgoing message.

1
Open the VBA Editor

Press Alt + F11 in your workbook to open the Visual Basic for Applications Editor, and navigate to the module containing your email macro.

2
Declare the Account Variable

Add a variable declaration for the account object at the beginning of your code: Dim OutAccount As Object (or Outlook.Account if early binding is used).

3
Create the Loop

Insert a loop to iterate through the accounts: For Each OutAccount In OutApp.Session.Accounts. Replace 'OutApp' with the name of your Outlook.Application variable.

4
Match the Email Address

Inside the loop, check if the account matches your target address: If OutAccount.SmtpAddress = "your.email@domain.com" Then.

5
Assign the Object

Within the If statement, assign the account to your mail item: Set OutMail.SendUsingAccount = OutAccount, followed by an Exit For statement to stop looping.

Assign an Outlook.Account Object to SendUsingAccount
Prevent Runtime Error 91: To avoid Runtime Error 91, add an error-handling check (e.g., If Not OutAccount Is Nothing Then) before attempting to send the email, ensuring a matching account was actually found.
Run VBA Macros Smoothly in WPS Office

Use WPS Spreadsheets for Seamless Macro Execution

WPS Office provides robust VBA support, allowing you to run automated scripts and interact with system applications like Outlook. You can easily manage, debug, and execute your email automation macros directly within WPS Spreadsheets.

  1. 1. Open Your Macro Workbook: Launch WPS Spreadsheets and open your .xlsm file containing the Outlook automation macro.
  2. 2. Access the Developer Tools: Navigate to the 'Tools' tab on the top ribbon and click 'VBA Editor' to view and modify your macro code.
  3. 3. Run the Automation: Ensure your Outlook client is open in the background, then execute your VBA script in WPS to dispatch the emails from the correctly assigned account.
Fully compatible with Microsoft Excel macro formats (.xlsm, .xlsb) and VBA code.Supports standard COM object integration for communicating with apps like Outlook.Free, lightweight, and fast alternative for heavy data automation tasks.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get Runtime Error 91 when setting SendUsingAccount?

Runtime Error 91 occurs when your VBA macro tries to assign an empty or undefined object. This usually happens if the loop finished without finding a matching SMTP address in your Outlook session, meaning the OutAccount object is null when the macro attempts to assign it.

Can I assign an email address string directly to SendUsingAccount?

No, the SendUsingAccount property strictly requires an Outlook.Account object. Passing a text string of the email address will result in a type mismatch or runtime error.

How do I ensure the Outlook Object Library is enabled?

In your VBA Editor, go to the top menu and select Tools > References. Scroll through the list and check the box for 'Microsoft Outlook XX.0 Object Library' (where XX represents your installed version), then click OK.