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

KarrillionAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
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

0
KarrillionAuthor Commented:
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.
0
David LeeCommented:
"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?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

David LeeCommented:
Assuming that you are okay with using a draft message, then here's the revised code for using it.  Replace the code from the first post with this code.  You'll also need to create a message with a subject of SendReply2All and save it int he Drafts folder.  
Sub SendReply2All()
    Dim olkMsg As Outlook.MailItem, _
        olkReply As Outlook.MailItem, _
        olkDraft As Outlook.MailItem
    Set olkDraft = Session.GetDefaultFolder(olFolderDrafts).Items.Find("[Subject] = 'SendReply2All'")
    If TypeName(olkDraft) <> "Nothing" Then
        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 = olkDraft.HTMLBody & .HTMLBody
                    Case Else
                        'Edit the plain-text version of your message on the next line'
                        .Body = olkDraft.Body & vbCrLf & vbCrLf & .Body
                End Select
                'Change the following line to .Send when youa re done testing'
                .Display
            End With
        Next
    End If
    Set olkDraft = Nothing
    Set olkReply = Nothing
    Set olkMsg = Nothing
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KarrillionAuthor Commented:
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!
0
KarrillionAuthor Commented:
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!
0
David LeeCommented:
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.  
0
KarrillionAuthor Commented:
Well, it appears to work well, thanks!
0
KarrillionAuthor Commented:
BlueDevilFan is really helpful, fast and thorough!
0
David LeeCommented:
You're welcome.  Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.