VBA Insert range into body of email without losing formatting and HTML signature

jr0124

New Member
Joined
Dec 28, 2016
Messages
16
Thank you in advance for your help!

I have had this set up to ask for the row and then use that to find the range to insert into the email. I am working on adding to it so that it will pull my signature to insert. I have found that I need to use HTMLBody in order to have my signature appear correctly. Otherwise, it pulls in all the saved HTML code.

But, when I use HTMLBody I lose all my formatting in the range I am pulling in. Since I am going to use this over quite a few other emails and the body range is quite the concatenate I'd prefer not to have to create that in HTML. Here is the code with the original Body Range and the changed one below.


Sub OfferApproval2()


On Error GoTo PROC_EXIT

'DECLARE AND SET VARIABLES
Dim Signature As String
Set otlApp = CreateObject("Outlook.<wbr>Application")
Set OtlNewMail = otlApp.CreateItem(olMailItem)
'-----------------------------<wbr>------------
'GET DEFAULT EMAIL SIGNATURE
Signature = Environ("appdata") & "\Microsoft\Signatures"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "Signature.htm")
Else:
Signature = ""
End If
Signature = CreateObject("Scripting.<wbr>FileSystemObject").GetFile(<wbr>Signature).OpenAsTextStream.<wbr>ReadAll
'-----------------------------<wbr>------------
'CREATE EMAIL
OtlNewMail.HTMLBody = Signature
With OtlNewMail
Rw = InputBox("What row number?")
If Rw = "" Then Exit Sub 'user clicked cancel
.To = Range("FU" & Rw).Text
.Subject = Range("FS" & Rw).Text
.Body = Range("FT" & Rw).Text & Signature
.Display
'.Send
End With
'-----------------------------<wbr>------------
'CLEANUP
Set OtlNewMail = Nothing
Set otlApp = Nothing
Set otlAttach = Nothing
Set otlMess = Nothing
Set otlNSpace = Nothing


PROC_EXIT:
On Error GoTo 0
Set OL = Nothing
End Sub


HTML Body
.HTMLBody = "<p><font face = ""arial""> This is where I was entering the range info </HTML> $ Signature
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

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