Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2018, 01:33 AM
fabien fabien is offline Outlook - Reply with greetings: "Hi (first name)," Windows 10 Outlook - Reply with greetings: "Hi (first name)," Office 2016
Novice
Outlook - Reply with greetings: "Hi (first name),"
 
Join Date: Apr 2018
Posts: 2
fabien is on a distinguished road
Default Outlook - Reply with greetings: "Hi (first name),"

Good afternoon everyone,

I am coming to you as I am trying to write a code that adds simple greetings when replying to an email: "Hi (sender's first name),"



I managed to get this code going and it works well, however my issue is the formatting, which I thought would have been an easy fix, however all my attempts failed...

My code below:

Code:
Sub AutoAddGreetingtoReplyAll()

    Dim oMail As MailItem
    Dim oReply As MailItem
    Dim GreetTime As String

  Select Case Application.ActiveWindow.Class
           Case olInspector
                Set oMail = ActiveInspector.currentItem
           Case olExplorer
                Set oMail = ActiveExplorer.Selection.Item(1)

    End Select

    Set oReply = oMail.Reply

With oReply

         .HTMLBody = "Hi " & Split(oMail.SenderName)(0) & "," & .HTMLBody
         .Display

    End With

End Sub
I have tried to replace the .HTMLBody line with the following, however while the "Hi" and "," get formatted with the correct font (font size comes up to 10pt...), my main issue is with & Split(oMail.SenderName)(0) &, that does not get formatted at all.

Code:
.HTMLBody = "<span style='font-size:11.0pt;font-family:""Century Gothic"" '>Hi </span>" & Split(oMail.SenderName)(0) & "<span style='font-size:11.0pt;font-family:""Century Gothic"" '>,</span>" & .HTMLBody
Appreciate your help.

Cheers,
Fabien
Reply With Quote
  #2  
Old 04-19-2018, 04:07 AM
gmayor's Avatar
gmayor gmayor is offline Outlook - Reply with greetings: &quot;Hi (first name),&quot; Windows 10 Outlook - Reply with greetings: &quot;Hi (first name),&quot; Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Use the Word document inspector to edit the message directly e.g. as follows. The only major snag with this is that not all senders have their sender names formatted as you might expect. Some, for example, have the surname first.

Code:
Sub AutoAddGreetingtoReplyAll()

Dim oMail As MailItem
Dim oReply As MailItem
Dim GreetTime As String
Dim olInsp As Inspector
Dim wdDoc As Object
Dim oRng As Object

    Select Case Application.ActiveWindow.Class
        Case olInspector
            Set oMail = ActiveInspector.currentItem
        Case olExplorer
            Set oMail = ActiveExplorer.Selection.Item(1)
    End Select

    Set oReply = oMail.Reply

    With oReply
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range
        .Display
        With oRng
            .collapse 1
            .Text = "Hi " & Split(oMail.SenderName)(0) & "," & vbCr
            .Font.Name = "Century Gothic"
            .Font.Size = 11
            .collapse 0
            .Select
        End With
    End With
lbl_Exit:
    Set oMail = Nothing
    Set oReply = Nothing
    Set olInsp = Nothing
    Set wdDoc = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-19-2018, 05:11 AM
fabien fabien is offline Outlook - Reply with greetings: &quot;Hi (first name),&quot; Windows 10 Outlook - Reply with greetings: &quot;Hi (first name),&quot; Office 2016
Novice
Outlook - Reply with greetings: &quot;Hi (first name),&quot;
 
Join Date: Apr 2018
Posts: 2
fabien is on a distinguished road
Default

Awesome work, thanks man, much appreciated.
Reply With Quote
Reply

Tags
vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook - Reply with greetings: &quot;Hi (first name),&quot; Outlook: Hyperlink shows "Microsoft Office" files not "ALL" Elly26 Outlook 5 02-22-2016 02:11 PM
Outlook 2003 Problem if I forward/reply to a message, it says "at least one active x controll elemen joe-msofficeforums Outlook 0 06-23-2015 04:51 AM
Wrong email address being used for "From" address when I reply Rosie Perera Outlook 0 04-20-2015 02:12 PM
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas jocke321 Word VBA 2 12-10-2014 11:27 AM
Outlook - Reply with greetings: &quot;Hi (first name),&quot; How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft