Generate outlook mail: Keep format of body and signature after pasting from word

mattisz

New Member
Joined
Jun 22, 2015
Messages
14
Hi there,

The code needs to loop through a range of contacts and, depending on one criteria, generate an outlook-email that uses the content of a selected wordfile as body. This all works perfectly, but I am not able insert a customized greeting and keeping the default signature without loosing the format.

The problem is that pasting the content of the Word file overwrites the e-mail body, and I am not able to get the syntax right when specifing where to paste the external content. When I try to use the .display and create a variable containing the signature (e.g., stdSignature = olEmail.body), I loose the formatting when putting it all together (e,g., .Body = strGreeting & vbNewline & strBody & vbNewline & stdSignature).

Currently, the relevant piece of code looks like this:

For Each i In listEmails.SpecialCells(xlCellTypeVisible)

If Cells(i.Row, "E").Value = "Not contacted" Then

strGreeting = "Dear" & Cells(i.Row, "B").Value
Set OlEmail = OlApp.CreateItem(0)

With OlEmail

.To = i.Value
.Subject = mailSubject
.BodyFormat = 3

Set wdEditor = .GetInspector.WordEditor
wdEditor.Content.Paste
Application.CutCopyMode = False

.Display
.Save
.Close 1

End With

Cells(i.Row, "E").Value = "Contacted"

End If

Next i



I hope you guys can help. I'll be happy to elaborate.

Thanks in advance.

/Mattisz
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Note that the greeting is not being used at the moment as I trimmed the code before pasting it but forgot to erase that part.
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,219
Members
453,024
Latest member
Wingit77

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