How to Fix Excel VBA Sending Email from the Wrong Outlook Account
Question details
The user needs their Excel VBA macro to send emails using a specific Outlook account, rather than defaulting to the primary 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.
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.
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.
Press Alt + F11 in your workbook to open the Visual Basic for Applications Editor, and navigate to the module containing your email macro.
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).
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.
Inside the loop, check if the account matches your target address: If OutAccount.SmtpAddress = "your.email@domain.com" Then.
Within the If statement, assign the account to your mail item: Set OutMail.SendUsingAccount = OutAccount, followed by an Exit For statement to stop looping.

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. Open Your Macro Workbook: Launch WPS Spreadsheets and open your .xlsm file containing the Outlook automation macro.
- 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. 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.

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.




