I have reached a few steps along the way to set up a standard template for Outlook emails in Excel 2016.
I would like to import comments into my email from the B column if the A column in the same row is marked with an "x". The comments comes from a sheet with many different ones to choose from (the idea is that one can pick the ones applicable for every individual email to save some time and standardize the procedure across the department).
The import is accomplished by running a For-loop over all the rows containing a comment.
However, the script also writes "True" before every copied comment and table in my email.
Furthermore, for every imported comment it adds a blank row.
- How can I supress the "true" statement for the comments in my email?
- How can I supress the "true" statement for the table in my email?
- How can import the comments without the extra blank row between them?
This is the part of my code for importing the cells containing a comment marked with "x" and a table:
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
With OutlookMail
.BodyFormat = olFormatHTML
.Display
.Subject = "Sizing Calculations - "& Range("C37")
.To = Range("C34").Value
.Display
Set xInspect = OutlookMail.GetInspector
Set pageEditor = xInspect.WordEditor
.HTMLBody = "ASSUMPTIONS:"& "<br><br>"'Set range to cover the assumptions to choose from
For i = 2 To 14
Sheets("COMMENTS").Select
If Cells(i, 1).Value = "x" Then
.HTMLBody = .HTMLBody & _
Sheets("COMMENTS").Range("B"& i).Copy
pageEditor.Application.Selection.Start = Len(.Body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.PasteAndFormat (wdFormatOriginalFormatting)
End If
Next i
.HTMLBody = .HTMLBody & "<br>"& _
"SIZING:"& "<br><br>"& _
Sheets("TABLES").Range("N1:P6").Value
Sheets("TABLES").Range("N1:P6").Copy
pageEditor.Application.Selection.Start = Len(.Body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.PasteAndFormat (wdFormatOriginalFormatting)
End With
My email comments turn out like this (in this case two comments are marked with "x"):
ASSUMPTIONS:
TrueCa(OH)2 quality: BET surface > 15 m2/g
TrueWater quality: default values