Link to home
Start Free TrialLog in
Avatar of Karrillion
Karrillion

asked on

Sending the same reply to multiple messages Outlook 2003

I've found several macros written by BlueDevilFan that come very close to doing what I need done for an autoreply macro, and I'm sure minor modification of one of those macros would fit the bill.

The closest question is this:  "I have a user that is a member of a recruitment group, and they are wanting to send a standard reply to multiple emails that they have received, is there any way of doing this in outlook.  as when you select multiple messages the reply option is greyed out."

Currently, the macro has almost what I need.  It replies to all highlighted emails and puts in standard text.

What I want added is this:
1) Reply uses the same subject as original email but inserts "RE:"
2) Reply keeps original email body and inserts my template's text above it (like a normal reply)
3) Macro can auto-send all the emails w/o me having to hit send for each one.  (I'd like to be able to enable/disable this part of the code just to verify it's working ok at first)

Original code is below.  

Thanks!


Sub SendReply2All() 
    Dim olkMsg As Outlook.MailItem, _ 
        olkReply As Outlook.MailItem, _ 
        olkTemp As Outlook.MailItem 
    For Each olkMsg In Application.ActiveExplorer.Selection 
        Set olkTemp = olkMsg.Reply 
        'Change the path and filename of the template on the next line 
        Set olkReply = Application.CreateItemFromTemplate("C:\SomeFolder\Template.oft") 
        olkReply.Recipients.Add olkTemp.Recipients.Item(1).Address 
        olkReply.Display 
        Set olkTemp = Nothing 
    Next 
    Set olkReply = Nothing 
    Set olkMsg = Nothing 
End Sub

Open in new window

Avatar of David Lee
David Lee
Flag of United States of America image

Hi, Karrillion.

This should do it.  The original code read in a completely preformatted that just needed to be addressed.  This version expects the message in the code.  I can change that to read it in if you prefer.  

You need to know that Outlook 2003 and earlier includes a security feature that prevents programs, scripts, and macros from sending messages without the user's express permission.  That security feature cannot be turned off, but there are ways to work around it.  Here are those ways.

1.  Sign the code.  Here's a link to instructions on doing that: http://msdn.microsoft.com/en-us/library/aa155754(office.10).aspx
2.  Use ClickYes (http://www.contextmagic.com/express-clickyes/), a small utility that'll click the Yes button for you.  It creates a security hole though, since a virus could start sending messages and ClickYes would click the Yes button for it too.  
3.  Use Redemption (http://www.dimastr.com), a COM library that enables code to safely bypass Outlook security.

Sub SendReply2All()
    Dim olkMsg As Outlook.MailItem, _
        olkReply As Outlook.MailItem
    For Each olkMsg In Application.ActiveExplorer.Selection
        Set olkReply = olkMsg.Reply
        With olkReply
            Select Case olkMsg.BodyFormat
                Case olFormatHTML
                    'Edit the HTML version of your message on the next line'
                    .HTMLBody = "Your HTML message goes here<br><br>" & .HTMLBody
                Case Else
                    'Edit the plain-text version of your message on the next line'
                    .Body = "Your plain text message goes here" & vbCrLf & vbCrLf & .Body
            End Select
            'Change the following line to .Send when youa re done testing'
            .Display
        End With
    Next
    Set olkReply = Nothing
    Set olkMsg = Nothing
End Sub

Open in new window

Avatar of Karrillion
Karrillion

ASKER

Thanks, David, it looks great!

I edited the lines you show in the code, but when I run it, no text appears in the reply.  What code would work to instead have it insert the text from an .oft template file?  That way it might be easier from a formatting perspective.
"no text appears in the reply"
Hmmmm.  I don't know how that's possible.  I tested before posting and it worked perfectly.  I'm not doubting you, I just don't know how the reply can not be there.  How about if you go back to the code just as I posted it and try that?  I'm concerned that editing those lines may have caused a problem.

"What code would work to instead have it insert the text from an .oft template file?"
I switched away from using an .oft file because it is a complete message, bot just the body.  How about using a draft message instead?  You'd create a draft with a given subject.  I could read the body from the draft.  Would that work for you?
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah, much better idea.  Making the oft file requires a person switch from Word as the email editor, so a draft is much easier.

I actually did try the code before editing the "body" sections but that came up empty as well.  I'll have to test again tomorrow when I go back to work and make sure I didn't somehow screw up the code.

I just go to tools/macro/macros/vbeditor right?
In the left pane I saw Project1 / Microsoft Office Outlook / ThisOutlookSession
In the right pane there was nothing at first, so I dbl-clicked ThisOutlookSession and the editor came up.
I pasted the code in there, pressed save, exited the vbeditor.
In Outlook, I highlighted a couple of test emails, went back to macros, chose the macro, clicked Run.
It created the emails with the old body, but not the new body.

Since I can't try this new code until tomorrow, I'll update you then.  Thanks again!
OK, Iied.  Forgot I had Outlook on my home machine.

I tested the code and it does indeed put the draft body into the email, and the Subject line is RE: <original subject text>

Oddly enough when I tested it with .Display, the original email body was not shown in the reply email.  When I changed it to .Send, I checked my Sent items and sure enough, the original email body was in the new email as it should be.  Why is that?

Thanks!
Sorry I omitted instructions on how to add the code to Outlook.  Here they are.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor


"Why is that?"
Sorry, I don't get the same behavior so I don't know.  Perhaps a quirk of using Word as the editor.  Word as the editor causes a number of problems in Outlook prior to 2007.  I never use it and don't recommend using it although I do understand why it's useful.  
Well, it appears to work well, thanks!
BlueDevilFan is really helpful, fast and thorough!
You're welcome.  Glad I could help.