Outlook 2007 'reply to all' in a macro.

A member of the dope very kindly gave me the following code to reply to a plain-text email in html. Unfortunately I forget who it was. But I’ve already thanked them :slight_smile:

Anyway. This code does a ‘reply’ email. In other words it replies to the first person in the ‘from’ field.


Option Explicit
Public Sub ReplyToPlainTextWithHTML()
   Dim HTMLReplyMail As Outlook.MailItem
 
   If Application.ActiveExplorer.Selection.Count Then
 
      If TypeOf Application.ActiveExplorer.Selection(1) Is Outlook.MailItem Then
 
         Set HTMLReplyMail = Application.CreateItem(olMailItem)
 
         HTMLReplyMail.To = Application.ActiveExplorer.Selection(1).SenderEmailAddress
         HTMLReplyMail.BodyFormat = olFormatHTML
         HTMLReplyMail.Subject = "Re: " & Application.ActiveExplorer.Selection(1).Subject
 
         Dim SigString As String
         SigString = "C:\Documents and Settings\" & Environ("username") & _
                                     "\Application Data\Microsoft\Signatures\compact.htm"
         Dim mailSig As String
         If Dir(SigString) <> "" Then
            mailSig = GetBoiler(SigString)
         Else
            mailSig = ""
         End If
          HTMLReplyMail.HTMLBody = "<br><br>" & mailSig & "<br>" & _
                                 "-----Original Message-----" & "<br>" & _
                                 "From: " & Application.ActiveExplorer.Selection(1).SenderName & "<br>" & _
                                 "Sent: " & Application.ActiveExplorer.Selection(1).SentOn & "<br>" & _
                                 "To: " & Application.ActiveExplorer.Selection(1).To & "<br>" & _
                                 "cc: " & Application.ActiveExplorer.Selection(1).CC & "<br>" & _
                                 "Subject: " & Application.ActiveExplorer.Selection(1).Subject & "<br>" & _
                                  Application.ActiveExplorer.Selection(1).HTMLBody
 
        HTMLReplyMail.Display
 
      End If
 
   End If
End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function


So my question is, how would I go about changing this code so that it does ‘reply to all’ instead of just ‘reply’?

I’ll give this one bump.

Sorry to not have an answer, but since you already seem a bit more advanced than I, do you know how to bind a key to a macro?

Looking at MSDN documentation for custom coding MS Outlook…

It looks like you’d have to iterate through all the names in the “To” and “Cc” properties and build (.Add) all the names in the “Recipients” collection property.

It’s more than just a minor tweak to a single line of code.

I have the macro set as a button on my toolbar…

Right click on the toolbar and click ‘customize’

then right click on the button you want to assign a key to. In the name, add an ampersand before one of the letters in the name. That letter becomes the shortcut key.

You need to pick a letter that isn’t already used by something else.

Mine is called ‘repy html’ so I put the ampersand before the ‘m’ and I hold alt-m to get the macro to run,

EDIT: There might be better ways to assign shortcut keys to tasks/macros in outlook, but the one above is the one I was able to figure out just now :slight_smile:

Thanks. It looks like I could get there if I spend some time on it.