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
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