Outlook 2013 and up have an option to always send new messages using the default email account.
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.
Text file containing both macros on this page.
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 SubSee 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)
See Using VBA Code if you need help using VBA code.
Text file containing both macros on this page.
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 SubNote: 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 = "alias@domain.com"
.BCC = "alias2@domain.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
Using VBA Code
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.
More Information
How to Enable the Developer Ribbon
See How to use VBA code samples in Outlook for more detailed information on using macros and selfcert.
Arjan says
Kudo's to you Diane !! Normally I get my "help" on stackoverflow but for my current job to automate sending an email from excel your articles and comments gave me all the help to do the job. thank u !!
John says
Hi Diane, is there a way we can specify the script to only run when e-mailing from a specific account. I have business and personal accounts in this case I would like the script only to send on behalf of when replying from my business account user@domain.com
Diane Poremsky says
You can use an If statement to either skip or send
For Each oAccount In Application.Session.Accounts
If oAccount = "business@account" Then
'do whatever
End if
next
John says
Thank you for the response. As I do not have much experience with coding could you show me where in this code I would add the proper statements. Also would it be possible to put a universal variable such as if oAccount source is *@xyz.com then set sender address to delegate@domain.com:
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objMailItem As Outlook.MailItem
Dim WithEvents myOlExp As Outlook.Explorer
Private Sub Application_Startup()
Initialize_handler
End Sub
Public Sub Initialize_handler()
Set objInspectors = Application.Inspectors
Set myOlExp = Application.ActiveExplorer
End Sub
Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olMail Then
Set objMailItem = Inspector.CurrentItem
If objMailItem.Sent = False Then
Call SetFromAddress(objMailItem)
End If
End If
End Sub
'Uncomment the next 3 lines to enable Outlook 2013/2016/2019/365 Reading Pane Reply
'Private Sub myOlExp_InlineResponse(ByVal objItem As Object)
' Call SetFromAddress(objItem)
'End Sub
Public Sub SetFromAddress(oMail As Outlook.MailItem)
' Set your preferred default From address below.
' Exchange permissions determine if it is actually stamped
' as "Sent On Behalf Of" or "Sent As".
' The address is not properly updated for the InlineResponse
' feature in Outlook 2013/2016/365. This is only a visual bug.
oMail.SentOnBehalfOfName = "delegate@domain.com"
End Sub
Josh says
I have this code that I use with a ribbon button:
Sub FORWESP()
Dim objMail, objForward As Outlook.MailItem
Dim BodyIni, BodyEnd As String
Set objMail = Outlook.Application.ActiveExplorer.Selection.Item(1)
Set objForward = objMail.Forward
BodyIni = objForward.Body
BodyEnd = "Dear Xxxx," & vbCrLf & vbCrLf & "blabliblabli blabli" & vbCrLf & vbCrLf & "Sincerely" & vbCrLf & BodyIni
With objForward
.Display
.Subject = "FW: " & objMail.Attachments.Item(1).FileName
.Body = BodyEnd
End With
End Sub
and now i want to also use a specific outlook account to send the email and I took this code from this page:
Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount = "x@xxx.com" Then
Set oMail = Application.CreateItem(olMailItem)
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
End Sub
But I am not smart enough to combine the two. Must be easy for someone who actually understands code... Would be great if someone could help...
Many Thanks
Josh
Diane Poremsky says
This works here -
Sub FORWESP()
Dim objMail, objForward As Outlook.MailItem
Dim BodyIni, BodyEnd As String
Dim oAccount As Outlook.Account
For Each oAccount In Application.Session.Accounts
If oAccount = "dianep@outlook-marketplace.com" Then
Set objMail = Outlook.Application.ActiveExplorer.Selection.Item(1)
Set objForward = objMail.Forward
objForward.SendUsingAccount = oAccount
End If
Next
BodyIni = objForward.Body
BodyEnd = "Dear Xxxx," & vbCrLf & vbCrLf & "blabliblabli blabli" & vbCrLf & vbCrLf & "Sincerely" & vbCrLf & BodyIni
With objForward
.Display
.Subject = "FW: " & objMail.Attachments.Item(1).FileName
.Body = BodyEnd
End With
End Sub
yvonne Chavez says
Hi Diane: can you tell me why some vba scripts "MakeItem" in their code and others use "msg.display" to view email templates.
Diane Poremsky says
Mailitem is used when you are opening a new message, .display displays the message.
michelle mason says
Hi.
RE: Macro for prepopulating a Subject within a current email (not a new one)
How do I get the macro to process within the email I am currently in instead of it populating a new one email altogether as soon as I engage the macro? I use a system client database called Applied EPIC and it works with outlook. I click on my client's email address within that database and it activates an outlook email window (EPIC is connected to Outlook). I hit ALT N→ AS to drop a prepopulated signature and then ALT N→Y to engage a macro (which I built to prepopulate the subject).
I already tried Quick Steps, and it is the same (only starts a new email when i want it to use the one I am in).
Here is the Macro
Sub New_Secure_Email()
Dim MItem As MailItem
Set MItem = Application.CreateItem(olMailItem)
MItem.subject = "friendly reminder; renewal 10/9/20"
MItem.Display
End Sub
Can i recode the macro so that it will work within the email i am in? When i use this one it pops up a *new email* which i cannot use because i need to use the one that happened in the beginning (because that one will store it in EPIC for me and i want to keep that trail).
Diane Poremsky says
This line calls for a new message:
Set MItem = Application.CreateItem(olMailItem)
You need to use activeinspector
Set MItem = Application.ActiveInspector.CurrentItem
michelle mason says
Thanks... that makes sense. HOWEVER, now i get an error message "The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros." I wasn't getting this message before. It worked (albeit, creating a new one.). Thoughts?
Diane Poremsky says
Are macros enabled in file > options > trust center > macro security?
michelle mason says
nevermind. I had changed back the set mltem by mistake and now using the one you suggested. IT's WORKING NOW.
Sub New_Secure_Email()
Dim MItem As MailItem
Set MItem = Application.ActiveInspector.CurrentItem
MItem.subject = "friendly reminder; renewal 10/12/20"
MItem.Display
End Sub
Sam says
Hi,
Some great stuff and pretty easy to follow . But I#m not sure I can make the next leap :-(
As part of a mail rule script I would like to forward an email having inserted some text and a picture (in line not as an attachment) before the email that triggered the rule (so just like a normal forwarding process.)
How can I do this with VBA?
TFAI
Matt says
Hello,
Could anyone direct a novice office user to assist in the following, I think it would be simple and functionality exist.
What I am trying to do is the following:
1) Report a Suspicious Email
2) On a email that has arrived I would like to set a button or method to
a) On selected email, forward to a mail box and then delete the original email.
b) Prefer to attach original email for header inspection.
Based on this we can review the original suspicious email and review prior to sending back to user. More for Phishing response due to amount of volume.
Basically I can view a inbox with suspicious email for review, with original attachment can inspect headers and URL in sandbox environment for inspection.
Dont expect it to be unique requirement so possibly a Macro or VSB script exists.
Can I use powershell as more experience on this tool than VBA ?
Diane Poremsky says
A macro can do it, not sure about powershell. i have this sample for spam reports - it includes the message header in the forward body.
https://www.slipstick.com/developer/code-samples/outlooks-internet-headers/#spam
David Boyd says
Wow, why is this so hard? What I need is to make sure that Mailmerge from Word uses my default account (gmail) rather than my hotmail account.
Diane Poremsky says
gmail is default for email and Hotmail is the default data file? The non-macro method is to make second profile with only the gmail account.
Andrew B says
Hi,
Basically my first time using VBA and have been all over youtube watching videos trying to learn. I have run into the issue of only being able to send the email when I run the macro. How can I get it to send every time I click on the command?
Diane Poremsky says
these samples are all manual options. the macros at https://www.slipstick.com/developer/code-samples/default-subject-messages/ show how to do something when the compose message form opens. You'd use this - m_Inspector.SendUsingAccount = olNS.Accounts.Item(1) - to set the account.
if you want every new message to be sent from the default account and use 2010, 2013 or 2016, there is an registry key always use the default account. See https://www.slipstick.com/outlook/outlook-2010/multiple-accounts-and-the-default-account/#sp1 for details.
Frumpy Jones says
Hi,
I'm not a VBA coder by any means and I tried this a few ways, but I'm running into an issue.
I tried to combine the code in this post with a another piece of code I have.
Cut to the chase: I have an oft file with formatting, and a signature line with a graphic and it looks great, but it keeps putting my default FROM field (I need it to use an e-mail address I have "SEND ON BEHALF" access to.
Is there some way to combine the code in this post with the following code, or is there a way in VBA to put in all my fancy-schmancy formatting?
Sub DoIt()Set msg = Application.CreateItemFromTemplate("C:UsersmynameAppDataRoamingMicrosoftTemplatesgreatteample.oft")
msg.Display
End Sub
Diane Poremsky says
Before .display, you need to set the sendonbehalfof address -
Sub DoIt()
Set msg = [snipped]
msg.SentOnBehalfOfName = "sales@domain.com"
msg.Display
End Sub
if it's another account in your profile (listed in File, Account settings), you need to do it slightly differently - use
msg.SendUsingAccount = olNS.Accounts.Item(2) ' where 2 is the second account in the accounts list
(put these two lines at the top of the macro -
Dim olNS As Outlook.NameSpace
Set olNS = Application.GetNamespace("MAPI"))
Adonal Arrington II says
Hey everyone, I have created a macro to send template emails using a button on the ribbon, I can't seem to figure out how to add a send on behalf function to my macro template. Admittedly I have very little training in VBA, all I can really do is take templates and try to wiggle them into my needs. Here is an example of my macro, how do I add in the "sendonbehalfofname" functionality?
Dim Template As String
Sub OpenTemplate1Thankyou
Template = "J:Thank you.oft"
MakeItem
End Sub
Diane Poremsky says
You'd use this in the makeitem macro - it needs to be set before you display the message.
newItem.SentOnBehalfOfName = "alias@domain.com"
Andres Acevedo says
So my question is, can I set a rule up that whenever a specific account receives an email with an attachment from a certain person it will download it to my chosen Directory on my computer?
I have a Macro that will look in to the email object and grab the attachment and download it. Kind of look like this...
Public Sub saveAttachtoDisk(itm As MailItem)
Dim objAtt As Outlook.Attachment
MsgBox "LRA1, LRA2, and Analyst1 have been updated"
Dim saveFolder As String
saveFolder = "M:RLB Customer ExperienceLRA_FileStorage"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
The thing is that I have two accounts set up and I want to make sure that it only works with one of the Outlook accounts.
Diane Poremsky says
You can create rules specific to one account - one of the conditions is received on account but if they are imap or exchange, they will have their own separate rules.
CHristian says
With the following code I have to try to block an account.
But when I save the mail -> close Outlook -> open Outlook -> Try to send the saved mail it comes to an error but I see no error message.
Private WithEvents Items As Outlook.Items'version: 0.11
Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.SendUsingAccount = "xxx@xxx.com" Then
MsgBox "Die Nachricht: " & Item.Subject & vbLf & "wurde von der E-Mail Adresse: " & Item.SendUsingAccount & " gesendet!!!", vbOKOnly + vbCritical
Cancel = True
End If
End Sub
Diane Poremsky says
use this to set the account
Dim oAccount As Outlook.Account
For Each oAccount In Application.Session.Accounts
If oAccount = "xxx@xxx.com" Then
msgbox "....
Russell says
I have been trying to get the .SentOnBehalfOfName function to work consistently. I have developed an outlook custom process that is distributed across multiple users that needs to send a receipt message to the sender once processing of their attachments is completed. The code scans a shared mailbox and the receipt message needs to come from the shared mailbox address
The code I have written works inconsistently. It works when the code is processed on my PC and when processed on one other individual. For 2 other individuals, the code works appropriately until the step where the receipt message is generated and sent
**PLEASE NOTE** all individuals have been setup as delegates with appropriate permissions to send on behalf of the mailbox - I have visually watched the mailbox owner configure each of these individuals.
The code executes a send command but the exchange server sends back an error email which is attached but modified to exclude mailbox names, email addresses etc.
This is my code:
With olMsg
.Attachments.Add Item, olEmbeddeditem
.Subject = "**ATTENTION PURCHASING TEAM: New Supplier Item Update Form(s) have been received for CMS Processing " & (Now)
.To = "someone@hotmail.com"
.CC = ""
.BCC = ""
.Body = Item.Body & StrBodySupplier
.SentOnBehalfOfName = "this is where the shared mailbox name string is"
.Save
SendInteger = 1
.Send
End With
Diane Poremsky says
Does the NDR give you any clues? Does the other person who it works for also have send as permissions to your mailbox? I'm thinking it's not using the person's account and is trying to use your account.
Adrian Knight says
Hello,
I was trying to achieve the same thing, but get the VBA script triggered when I click "Reply" / "replyall" / "Forward". If I run the macro from the MVB directly it opens the selected message and replaces my from address field with the default account. I just can't get it to work when I click "Reply" on an email.
So the end-goal: When I click reply/replyall/forward on messages on another account in Outlook 2010 (autodiscover , exchange accounts), to have the FROM address always one specific account (default one pref).
Diane Poremsky says
you need a macro that runs when you click the reply/forward buttons.
See https://www.slipstick.com/developer/vba-when-reply-is-clicked/ for examples. put your code for selecting the account in the last code sample on the page and it should work fine. (you may need to put your code before oresponse.display, not after)
Economy says
For "Reply" / "Replyall" / "Forward" use this:
Public Sub ReplyBySpecAccount()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount.DisplayName = "Name_of_Default_Account" Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
End Sub
Public Sub ReplyAllBySpecAccount()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount.DisplayName = "Name_of_Default_Account" Then
Set oMail = Application.ActiveExplorer.Selection(1).ReplyAll
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
End Sub
Public Sub ForwardBySpecAccount()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount.DisplayName = "Name_of_Default_Account" Then
Set oMail = Application.ActiveExplorer.Selection(1).Forward
oMail.SendUsingAccount = oAccount
oMail.Display
End If
Next
End Sub
Need to asign 3 macros:
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.
Mark says
Diane,
Is there any way to programmatically verify if email was actually sent, when sending emails with MS Outlook from VBA?
Diane Poremsky says
you'd need to check the sent items folder - maybe get the to and subject when its added to the sent folder and compare it to the one you thought you sent. Once it leaves Outlook, the only way to confirm it reached the recipient is with using read and delivery receipts, which are notoriously unreliable. Or using "web bugs", which are also unreliable.
Dale Frey says
Hi Diane
I very much appreciate you sharing your knowledge on this page it is helpful.
I do have a question, when replying to existing mail in a secondary account how would I by default be able to have the From address be different from my personal mail account by default?
I am on Outlook 2010 and have a support account automatically open for quick navigation between my personal and business accounts. The code above works great for new messages but not being a programmer, I am lost on what changes I can make to better myself. Appreciate your advice.
Diane Poremsky says
The code sample at https://www.slipstick.com/outlook/email/reply-replyall-attachments/ shows how to do something when you hit the reply button - try merging the two macros.
Jamie M. says
Thanks for the great code Diane! I tried to get the reply button VBA code working with the "use default from account" code above but to no avail. I'm not very experienced with VBA. If possible could you write the VBA code for a "reply" button that uses the "default" account reguardless of the account the message came in on? Thanks!
-Jamie M.
Diane Poremsky says
For replies, it would be better to pick up the reply button click (I'll add code for it)... but if the account is POP3 or IMAP and you want to always reply using a specific account, you can change the SMTP information on the account to the desired account, similar to the method shown here. The sending account's email address and display name goes at the top, along with it's SMTP server name.
Jamie M. says
It's exchange, hence why I can't change the SMTP information. I have to use a dummy outgoing account, and need it to default to it always, even for replies. If it could pick up the real reply button click that would be amazing! Thanks again :)
-Jamie M.
Diane Poremsky says
Unless you have an Exchange account that does not have SMTP enabled, you could use a dummy account. (GoDaddy's Office 365 doesn't enable SMTP, not sure about other resellers. )
In any event, I'll see what I come up with. I'm working on a macro for a company that uses single member distribution groups to send from additional addresses. After it's finished and tested I'll post it here.
Suraj Singh says
HI,
I am new to VBA and recently started working on Macros with Excel.
I have a problem. I have two outlook Profiles say Profile A and Profile B. When I created a macro in the Excel using VBA, with specific user ID's who belong to Profile B. I have also created a button in Excel sheet which when clicked will open an Outlook email with those ID's in "cc" column. Now, my problem is when I click on the create button in Excel sheet Profile A's Outlook is being generated and the user ID's do not belong to Profile A. How can I change the Outlook profile in VBA or Excel or set the outlook profile name to a specific profile. Kindly help.
Diane Poremsky says
I'm guessing Profile A is set as default or Outlook is open to that profile. If outlook isn't running, code will open the default profile. If you have outlook set to ask which profile, then it should ask you which to use. If outlook is running, it's going to use the profile that is open.
Diane Poremsky says
Are you using the meeting request code?
Michael says
Thank you so much for this VBA code. I have been searching for days for this.
JDL says
I am truly having a hard time with this.
I run Outlook 2013 against Exchange server.
I am connected to two Exchange accounts. My personal one is just my name at my instution (jlevine@acme.edu), and I was recently made the coordinator for another department and given full permissions over the department's e-mail (LAP@acme.edu).
I am trying to set up User-Defined Forms that allow me to send various form e-mails, form meeting requests, and things of the sort very quickly, so I am saving them as .OFT files and I am using your simple macro and attaching those to buttons on a custom ribbon to call them up in a single click! For routine E-MAIL messages, it works like a charm. I created them while working in the LAP account, and when I call it up, it comes up automatically as being sent FROM the LAP account (just the way I want it!)
For MEETING REQUESTS, though, not so much. I CREATED the .OFT while working in the LAP account, then saved the macro and attached it to a button, but when I call up the meeting request macro, there is virtually NO "From" option. In fact, it's blank. When I do send that meeting request to its intended recipients, it shows up in their email as coming from "jlevine@acme.edu ON BEHALF OF LAP@acme.edu." I cannot change this at all. There's no option to change the "From" account.
The funny thing is that when I create a meeting request MANUALLY, going through the steps from scratch, I can send the request from whatever account I want. It's ONLY when I create an .OFT template that it won't let me choose the FROM account.
What is it I'm not seeing/knowing/doing right?!?! This is frustrating!
Thank you for whatever feedback you afford me in advance!
Diane Poremsky says
I'll have to test this and check out the different scenarios.
Jayson Levine says
Thank you! I will be eager to know what you find on this one! I don't have much hair, but what I have, I'm pulling out! I can't imagine why I'd be perfectly able to choose the account from which I send a meeting request manually/from scratch, but be completely locked out from any choice in the matter by creating a meeting request user form .oft file aand bringing that up either through the standard "Choose a Form" method or by executing a macro that quickens the process.
FP says
Thank you for this. Very helpful. Only trouble I had was with the instructions on changing macro security for the 2010 version. I found it at File Tab/Options/Trust Center/Trust Center Settings/Macro Settings. And then I selected Notifications for all macros.
Dave Englund says
Diane, thanks for providing these code snippets! Now, I have a question :D
We currently use a bit of code called "ReplyWithAttachments" because Outlook does not include attachments in a Reply All, and our Help Desk needs to include the original attachments on all our correspondence. So, we use this nifty "ReplyWithAttachments" code to do that. Now, what I'm wondering is, would you be able to incorporate your "using a specific account" code into our "ReplayWithAttahments" code? This would solve some problems for us, in that we could ensure that when we use this our "From" will always be the Help Desk address rather than our personal address. Here's the "ReplyWithAttachments" code:
'
Sub ReplyWithAttachments()
' Keyboard Shortcut: Ctrl+w
Dim rpl As Outlook.MailItem
Dim itm As Object
Set itm = GetCurrentItem()
If Not itm Is Nothing Then
Set rpl = itm.ReplyAll
CopyAttachments itm, rpl
rpl.Display
End If
Set rpl = Nothing
Set itm = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select
Set objApp = Nothing
End Function
Sub CopyAttachments(objSourceItem, objTargetItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
strPath = fldTemp.Path & "\"
For Each objAtt In objSourceItem.Attachments
strFile = strPath & objAtt.FileName
objAtt.SaveAsFile strFile
objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
fso.DeleteFile strFile
Next
Set fldTemp = Nothing
Set fso = Nothing
End Sub
'
Robert says
I want to thank you so much for this, I have searched literally for years on how to email from specific accounts without having to remember to switch accounts in the email. Such a lifesaver.