Extract Names from Senders in Reply and Add to Greeting Outlook VBA

learningVBA321

New Member
Joined
Jul 10, 2017
Messages
30
Hello everyone,

I have some code here that currently works to create a reply, take the sender's name, and put it in the greeting. It also adds wording for the body and then a signature. What I need to do is get Outlook to pull all the names from the sender field and be able to add them to the reply as well.

So, you have the sender as Name1; Name 2 in the from fields from the original received email (they become the To fields in the reply).
I currently get this in my reply using the code below: Dear Name1,

I want to have it get Dear Name1 but then also assign a value to Name2. One that I could either put somewhere in the body (preferable) or at least have it add to the greeting. I know I can pull them as a string, but I want to treat each name individually, as I might need to put them in a place other than just the greeting.

I got some of this from Ron DeBruin and then added my own and some other coding. Can anyone help?

Thanks!

Code:
Sub AutoAddGreetingtoReply()
    Dim oMail As MailItem
    Dim oReply As MailItem
    Dim GreetTime As String
 Dim strbody As String
 Dim SigString As String
    Dim Signature As String
    Dim R As Outlook.Recipient
   
     
    Select Case Application.ActiveWindow.Class
           Case olInspector
                Set oMail = ActiveInspector.CurrentItem
           Case olExplorer
                Set oMail = ActiveExplorer.Selection.Item(1)
    End Select
    
 
 
  strbody = "<H3><B></B></H3>" & _
  "<br><br><B></B>" & _
              "Please visit this website to view your transactions.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<A HREF=""http://www.google.com"">Questions</A>" & _
              "<br><br>Thank you"
              
              SigString = Environ("appdata") & _
                "\Microsoft\Signatures\90 Days.htm"

    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If
   
    Set oReply = oMail.ReplyAll
 
    With oReply
        .CC = ""
        .HTMLBody = "<Font Face=calibri>Dear " & oMail.SenderName & "," & r1 & strTo & strbody & "<br>" & Signature
        .Display
    End With
    
    End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Anyone? Did I put this in the right forum? This is the one that said non-Excel issues. I am going to try the main forum, as it mentions excel/VBA and this is a VBA question.
 
Upvote 0

Forum statistics

Threads
1,223,762
Messages
6,174,353
Members
452,557
Latest member
savvaskef

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top