rr2r
asked on
Outlook 2016 VBA Macro -Reply to email witha custom "from" address...
Hello,
I am trying to automate one of the processes for our marketing department and they would like to be able to respond to some emails with a group "from address". My initial idea was to create a shared account to which all of them would have access and channel said emails there. However I am wondering if similar thing could not be achieved with a Macro. It would need to create a replay message to currently selected email, and would also need to set the "from" address to something predetermined in Macro versus the default "from" address that the Outlook would be normally using. I have found the following script that accomplishes the reply part but I am not sure how to make modify it so that a custom "from" address would be used.
Thanks!
Script:
I am trying to automate one of the processes for our marketing department and they would like to be able to respond to some emails with a group "from address". My initial idea was to create a shared account to which all of them would have access and channel said emails there. However I am wondering if similar thing could not be achieved with a Macro. It would need to create a replay message to currently selected email, and would also need to set the "from" address to something predetermined in Macro versus the default "from" address that the Outlook would be normally using. I have found the following script that accomplishes the reply part but I am not sure how to make modify it so that a custom "from" address would be used.
Thanks!
Script:
Option Explicit
Sub ReplyMSG()
Dim olItem As Outlook.MailItem
Dim olReply As MailItem ' Reply
Dim olRecip As Recipient ' Add Recipient
For Each olItem In Application.ActiveExplorer .Selection
Set olReply = olItem.ReplyAll
Set olRecip = olReply.Recipients.Add("Em ail Address Here") ' Recipient Address
olRecip.Type = olCC
olReply.HTMLBody = "Hello, Thank you. " & vbCrLf & olReply.HTMLBody
olReply.Display
'olReply.Send
Next olItem
End Sub
Sub ReplyMSG()
Dim olItem As Outlook.MailItem
Dim olReply As MailItem ' Reply
Dim olRecip As Recipient ' Add Recipient
For Each olItem In Application.ActiveExplorer
Set olReply = olItem.ReplyAll
Set olRecip = olReply.Recipients.Add("Em
olRecip.Type = olCC
olReply.HTMLBody = "Hello, Thank you. " & vbCrLf & olReply.HTMLBody
olReply.Display
'olReply.Send
Next olItem
End Sub
ASKER
This is a sample code I found that does the "SandAs" part so it is a matter of combining the two now I would imagine...
Sub CustomMailMessage()
Dim OutApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients
Set OutApp = CreateObject("Outlook.Appl ication")
Set objOutlookMsg = OutApp.CreateItem(olMailIt em)
Set Recipients = objOutlookMsg.Recipients
Set objOutlookRecip = Recipients.Add("alias@doma in.com")
objOutlookRecip.Type = 1
objOutlookMsg.SentOnBehalf OfName = "sales@domain.com"
objOutlookMsg.Subject = "Testing this macro"
objOutlookMsg.HTMLBody = "Testing this macro" & vbCrLf & vbCrLf
'Resolve each Recipient's name.
For Each objOutlookRecip In objOutlookMsg.Recipients
objOutlookRecip.Resolve
Next
'objOutlookMsg.Send
objOutlookMsg.Display
Set OutApp = Nothing
End Sub
Dim OutApp As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients
Set OutApp = CreateObject("Outlook.Appl
Set objOutlookMsg = OutApp.CreateItem(olMailIt
Set Recipients = objOutlookMsg.Recipients
Set objOutlookRecip = Recipients.Add("alias@doma
objOutlookRecip.Type = 1
objOutlookMsg.SentOnBehalf
objOutlookMsg.Subject = "Testing this macro"
objOutlookMsg.HTMLBody = "Testing this macro" & vbCrLf & vbCrLf
'Resolve each Recipient's name.
For Each objOutlookRecip In objOutlookMsg.Recipients
objOutlookRecip.Resolve
Next
'objOutlookMsg.Send
objOutlookMsg.Display
Set OutApp = Nothing
End Sub
ASKER
@Bill Prew - no I have not tried that.
ASKER
Not seeing any info as far as how to use that option... What is the proper syntax for this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It does 90% of what I need. A small modification would make it perfect:
1) Remove the additional address from the CC field - I don't think we have a need for that.
2) Do not put anything in the body of the email automatically - the response will be customized every time.
Take a look at the image for the areas highlighted. When I tried to simply remove the lines with appropriate code the Macro stopped working altogether - I am really not good at this VBA thing :(
Thanks!
ThisOne.PNG
1) Remove the additional address from the CC field - I don't think we have a need for that.
2) Do not put anything in the body of the email automatically - the response will be customized every time.
Take a look at the image for the areas highlighted. When I tried to simply remove the lines with appropriate code the Macro stopped working altogether - I am really not good at this VBA thing :(
Thanks!
ThisOne.PNG
Okay, this removes the additional recipients as well as any body text.
»bp
Sub ReplyMSG()
Dim olItem As Outlook.MailItem
Dim olReply As MailItem ' Reply
For Each olItem In Application.ActiveExplorer.Selection
Set olReply = olItem.ReplyAll
olReply.SentOnBehalfOfName = "sales@domain.com"
olReply.Display
'olReply.Send
Next olItem
End Sub
»bp
ASKER
Thanks!
MailItem.Sender Property (Outlook)
»bp