![]() |
|
|
|
#1
|
|||
|
|||
|
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
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 Cheers, Fabien |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
Awesome work, thanks man, much appreciated.
|
|
| Tags |
| vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
How to choose a "List" for certain "Heading" from "Modify" tool?
|
Jamal NUMAN | Word | 2 | 07-03-2011 03:11 AM |