Outlook VBA to send from Non-default Account & Data Files

Jacques

New Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Operating system::    Windows 11 Pro
Outlook version:     Microsoft 365 V2403
Email type or host:    POP

Diane Poremsky helped me in 2014 to code VBA script below in order to send out batch mails for invoicing and statements.

The problem is that since about 2 months ago Outlook sends from my default account and Data file selected which is linked to my Accounting Software that generates the mails. No matter what I do and add to the VBA, the final e-mail is sent from my default account. I place a pause in the VBA to check what is saved and it even saves the correct From Account but after sent it defaults back to my default account. It seems that Outlook uses the default DATA File selection to detemine the account from which to send and not only the default email account setting? I cannot change my Default Data File as all my TASKS and links with iStore etc uses the default setting.

Sub ChangeSubject()

Dim myolApp As Outlook.Application

Dim aItem As Variant 'As Object

Set myolApp = CreateObject("Outlook.Application")

Set mail = myolApp.ActiveExplorer.CurrentFolder.Items

Dim i As Long

Dim strTemp As String

Dim intCount As Integer

On Error Resume Next

intCount = mail.Count

For i = intCount To 1 Step -1

Set aItem = mail.Item(i)

strTemp = "Add to Left Subject" & aItem.Subject & "Add to Right Subject"

aItem.Subject = strTemp

aItem.SendUsingAccount = "xyz.org.za" (added today to try solution)
aItem.SentOnBehalfOfName = "xyv.org.za" (added today to try solution)

aItem.Save

aItem.Send

Next i

Set myolApp = Nothing

End Sub
 
the final e-mail is sent from my default account
Are you using mail merge? That will always use the default data file account.

I'll test the code - have another person who wants to change the From address but now it reverts to the account address when it worked like he wanted it previously.
 
Are you using mail merge? That will always use the default data file account.

I'll test the code - have another person who wants to change the From address but now it reverts to the account address when it worked like he wanted it previously.
Hi Diane, much appreciated. I use SAGE accounting and run my invoice batch for let's say 150 clients. The software generates the 150 invoices which end up in my Default Outbox (I disconnect my Network in order to block the mail being sent). I then move all 150 emails from the Default Outbox to the DRAFT folder of the account from which I want to send. Then I run the macro with changes to my Subject for Example: I add "Levies Invoiced - May 2024". The macro worked like a charm until about 2 months back. As I send out invoices on behalf of clients on a outsourced basis, I have done this for years on end and from many different accounts (Setup each as a separate Outlook Data File and e-mail account). So the mails are moved to the DRAFT Folder of the required e-mail account, I then switch back on my Network (Enable) and run the macro. What's always been weird is that even though it worked using the SENT from account as being correct, all mail ended up in my Default Sent Items Folder. I then just moved them to the other Data File's Sent Folder.
 
Are you using mail merge? That will always use the default data file account.

I'll test the code - have another person who wants to change the From address but now it reverts to the account address when it worked like he wanted it previously.
Hi Diane - Just following up if you found a solution? Thanks in advance
 
Good Evening Diane - I have tried everything and my only solution was to edit each mail and select the correct e-mail account and press send. The e-mail then moves from my default outbox/draft to the correct account's outbox. Is there a way to record a macro to that I can capture my actions in the VBA code:

1719524155587.png
1719524155587.png
 
Similar threads
Thread starter Title Forum Replies Date
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
D Outlook VBA to open Excel attachment and send recipient's email address to a workbook cell? Using Outlook 4
H Problems With Outlook 2013 VBA To Send and Print an email Outlook VBA and Custom Forms 1
M VBA Send Sales reports using .oft files, originate in Outlook or Excel? Using Outlook 5
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
M Outlook 2016 outlook vba to look into shared mailbox Outlook VBA and Custom Forms 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
BartH VBA no longer working in Outlook Outlook VBA and Custom Forms 1
W Can vba(for outlook) do these 2 things or not? Outlook VBA and Custom Forms 2
richardwing Outlook 365 VBA to access "Other Actions" menu for incoming emails in outlook Outlook VBA and Custom Forms 0
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
C Outlook (desktop app for Microsoft365) restarts every time I save my VBA? Using Outlook 1
E Outlook 365 Outlook/VBA Outlook VBA and Custom Forms 11
J VBA for outlook to compare and sync between calendar Outlook VBA and Custom Forms 1
E Outlook VBA change GetDefaultFolder dynamically Outlook VBA and Custom Forms 6
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
K Outlook Office 365 VBA download attachment Outlook VBA and Custom Forms 2
V vBA for searching a cell's contents in Outlook and retrieving the subject line Outlook VBA and Custom Forms 1
B vBA for exporting excel file from outlook 2016 Outlook VBA and Custom Forms 3
S Excel vba code to manage outlook web app Using Outlook 10
H Custom Outlook Contact Form VBA Outlook VBA and Custom Forms 1
S Problem Checking the available stores in my Inbox (Outlook VBA) Outlook VBA and Custom Forms 0
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
O VBA Outlook Message Attachment - Array Index Out of Bounds Outlook VBA and Custom Forms 0
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
G Outlook VBA and Google Calendar ("Events") Outlook VBA and Custom Forms 1
J VBA Outlook : Subject line : Cut and Paste name to heading , number to very end of the body of Email Outlook VBA and Custom Forms 1
B Advanced Search in MS Outlook by VBA and SQL Outlook VBA and Custom Forms 2
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S Find a cell value in excel using outlook vba Using Outlook 1
J Execute Add-In Button from VBA Outlook 2016 Outlook VBA and Custom Forms 1
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5

Similar threads

Back
Top