VBA Run When Reply

John Booze

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
Hi Diane, can you help me with VBA code to be used in Outlook 2013. This is what I would like to do:
1. I will select Reply To All and then run the code.
2. The code will add an attachment, insert certain text to the top of the body of the email reply, and insert my signature under the text.
Please me know if you can assist with this or point me to a source that can?
Thank you, John
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
code sample here to do something when you hit the reply/reply all, or forward button - i believe it includes a code sample to add text while keeping the original body as is : VBA Sample: Do Something When Reply is Clicked

this article shows how to add text if its not in the one above: Run a script rule: Reply to a message

Adding attachments is fairly simple:
oResponse.Attachments.Add "C:\path\to\filename.docx"

signature should be added automatically, if not, i have code at slipstick that does that too.
 

John Booze

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
Hi Diane,
I found a script that might help me. But I'm am having problems testing it. Here is what's happening and the questions I have:
1. When I try to run the script I get an empty macro window with nothing in it (see attached)?
2. From what I have read all macro's for Outlook must be contained in ThisOutlookSession. How can you create and call more than one macro if they are all in the same place in VBA (see attached).
Any advice or links would be appreciated.
Thank you, John
 

Attachments

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The macro name format - sub whatever (item as outlook.mailitem) - indicates it's a macro that is called by a rule using run a script action.

To test it with out using a rule or sending messages (or if you just want to run it manually) use this to call it - change YourMacroName to the name of your run a script macro - it will run on the selected message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
The macros at VBA Sample: Do Something When Reply is Clicked run everytime you click reply, repluall, or forward. some of the samples only show reply - copy the reply macro and change the name for replyall or forward

Copy:
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
' bunch of code
Set oResponse = oItem.Reply
end sub

then change reply to replyall or forward in the name and in the set line.
 

John Booze

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
The macro name format - sub whatever (item as outlook.mailitem) - indicates it's a macro that is called by a rule using run a script action.

To test it with out using a rule or sending messages (or if you just want to run it manually) use this to call it - change YourMacroName to the name of your run a script macro - it will run on the selected message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
The macros at VBA Sample: Do Something When Reply is Clicked run everytime you click reply, repluall, or forward. some of the samples only show reply - copy the reply macro and change the name for replyall or forward

Copy:
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
' bunch of code
Set oResponse = oItem.Reply
end sub

then change reply to replyall or forward in the name and in the set line.
The macro name format - sub whatever (item as outlook.mailitem) - indicates it's a macro that is called by a rule using run a script action.

To test it with out using a rule or sending messages (or if you just want to run it manually) use this to call it - change YourMacroName to the name of your run a script macro - it will run on the selected message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
The macros at VBA Sample: Do Something When Reply is Clicked run everytime you click reply, repluall, or forward. some of the samples only show reply - copy the reply macro and change the name for replyall or forward

Copy:
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
' bunch of code
Set oResponse = oItem.Reply
end sub

then change reply to replyall or forward in the name and in the set line.
The macro name format - sub whatever (item as outlook.mailitem) - indicates it's a macro that is called by a rule using run a script action.

To test it with out using a rule or sending messages (or if you just want to run it manually) use this to call it - change YourMacroName to the name of your run a script macro - it will run on the selected message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
The macros at VBA Sample: Do Something When Reply is Clicked run everytime you click reply, repluall, or forward. some of the samples only show reply - copy the reply macro and change the name for replyall or forward

Copy:
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
' bunch of code
Set oResponse = oItem.Reply
end sub

then change reply to replyall or forward in the name and in the set line.
The macro name format - sub whatever (item as outlook.mailitem) - indicates it's a macro that is called by a rule using run a script action.

To test it with out using a rule or sending messages (or if you just want to run it manually) use this to call it - change YourMacroName to the name of your run a script macro - it will run on the selected message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
The macros at VBA Sample: Do Something When Reply is Clicked run everytime you click reply, repluall, or forward. some of the samples only show reply - copy the reply macro and change the name for replyall or forward

Copy:
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
' bunch of code
Set oResponse = oItem.Reply
end sub

then change reply to replyall or forward in the name and in the set line.
The macro name format - sub whatever (item as outlook.mailitem) - indicates it's a macro that is called by a rule using run a script action.

To test it with out using a rule or sending messages (or if you just want to run it manually) use this to call it - change YourMacroName to the name of your run a script macro - it will run on the selected message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As Object ' MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
YourMacroName objItem

End Sub
The macros at VBA Sample: Do Something When Reply is Clicked run everytime you click reply, repluall, or forward. some of the samples only show reply - copy the reply macro and change the name for replyall or forward

Copy:
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
' bunch of code
Set oResponse = oItem.Reply
end sub

then change reply to replyall or forward in the name and in the set line.
Hello Diane, I still need help.
1. When working with Outlook and VBA will I always be placing my code within "ThisOutlookSession?"
2. Is this how you are saying to call a Macro(Sub)?
Diane, can you point me to 2 simple codes where I can get the feel of saving and calling different Macro(Sub)s when I am calling routines in Outlook?
I appreciate your quick responses.

upload_2017-7-19_9-12-39.png
 

Top