Outlook macro - new email - how to set font

M

Mark

Hi

A while since I worked on this.

From previous threads I've created a macro that I click and it replies
to an email with "Dear John" or whatever using the code (in part)

NewMsg.Body = "Dear " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, " ") - 1) _
& "," & vbCr & vbCr & vbCr

Trouble is the font is different in my new email when I hit enter
after "Dear John"

How do I set the font here?

Mark

BTW the full code is:

Sub Dear_Name()
Dim myItem As Outlook.MailItem
Dim NewMsg As Outlook.MailItem

' get valid ref to current item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set myItem = ActiveExplorer.Selection.Item(1)
myItem.Display
Case "Inspector"
Set myItem = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0

If myItem Is Nothing Then
MsgBox "Could not use current item. Please select or open a
single email.", _
vbInformation
GoTo ExitProc
End If

Set NewMsg = myItem.Reply

NewMsg.Body = "Dear " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, " ") - 1) _
& "," & vbCr & vbCr & vbCr & "Regards, ..." & vbCr & vbCr &
"_____________________________________________" _
& vbCr & "From: " & (myItem.SenderName) & vbCr & "Sent: " &
(myItem.SentOn) & vbCr & "To: " & (myItem.To) & vbCr & "Subject: " &
(myItem.Subject) & vbCr & vbCr & myItem.Body
myItem.Close olDiscard
NewMsg.Display

'Edit "Regards, ..." to whatever you want

ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub
 
K

Ken Slovak

If the format of the email is HTML you will need to use HTML coding and tags
for the font settings, using HTMLBody and not Body.
 
M

Mark

If the format of the email is HTML you will need to use HTML coding and tags
for the font settings, using HTMLBody and not Body.

Many thanks Ken

New territory for me.
I tried this, but it did not work, it gives an error on the
first"<":
NewMsg.HTMLBody = <font face="Arial"> "Dear " & Left$
(myItem.SenderName, InStr(1, myItem.SenderName, " ") - 1) _
& "," & vbCr & vbCr & "Regards, Martin" </font>

Any help would be appreciated

Mark
 
K

Ken Slovak

The best way to see what to do is to view the existing HTMLBody property in
an email formatted the way you want. Select an email like that in the folder
view and then open the Outlook VBA project (Alt+F11). Show the Immediate
window if it's not open and enter the following there:

? Application.ActiveExplorer.Selection(1).HTMLBody

Place your cursor in that line and press Enter to execute that line of code.
The actual raw HTML will be output to the Immediate window. You can then use
copy and paste to copy that to Notepad to view.

That's about the best way I've found to see what's going on and what needs
to be done to format things.




If the format of the email is HTML you will need to use HTML coding and
tags
for the font settings, using HTMLBody and not Body.

Many thanks Ken

New territory for me.
I tried this, but it did not work, it gives an error on the
first"<":
NewMsg.HTMLBody = <font face="Arial"> "Dear " & Left$
(myItem.SenderName, InStr(1, myItem.SenderName, " ") - 1) _
& "," & vbCr & vbCr & "Regards, Martin" </font>

Any help would be appreciated

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top