Email HTMLbody and HTML Filler Object

Email HTMLbody, HTML

The HTMLFiller object is used to fill bookmarked locations in a HTML document – the HTMLBody property of an email or an HTML page containing with data. The HTMLFiller is added to your VBA project when you create an Outlook email process using Document Creation using Microsoft Access.

Bookmarks

Bookmarks normally correspond to the name of the field or control that provides the data.

Bookmarks are used in two ways:

  1. strings like [CompanyID] with square brackets surrounding the bookmarkname are simply intended to be replaced by a data value.
  2. The value of id attributes for identifying more complex elements such as an image, a list or a table.
Outlook Email HTMLBody Template Designer
Outlook Email Body HTML Template Designer showing bookmarks where the document will be filled with data from the database.

Set HTMLBody from template filled with data


Dim appOutlook As Outlook.Application
  Set appOutlook = New Outlook.Application
  Dim mimEmail As Outlook.MailItem
  Set mimEmail = appOutlook.CreateItem(olMailItem)
  Dim hfr As New HTMLFiller
  hfr.Load FileName:=strTemplateFile
  hfr.FillPicture Bookmark:="Image", ImageFile:=ControlValue(control:=![Image])
  hfr.InsertFile Bookmark:="HTMLFile", FileName:=ControlValue(control:=![HTMLFile])
  hfr.FillElement Bookmark:="Usage", Value:=ControlValue(control:=![Usage])
  hfr.FillListFromArray Bookmark:="ListofReasonssubform", Array1D:=ValuesInSubFormColumn( _
    control:=![List of Reasons subform],ColumnControlName:="Reason")
  mimEmail.HTMLBody = hfr.HTML

Methods

Most methods below concern different ways data is used to fill areas in the template HTML file on bookmarked locations. For example in case of an Image element <img> with id ‘myimage’ the supplied data will be used to fill the source src attribute with the file location of the picture.

Inserts a hyperlink at the bookmarked location.


Public Sub AddHyperlink(Bookmark As String, Value As Variant, Optional ParseValue As Boolean = False, _ 
Optional TextToDisplay As String, Optional SubAddress As String)

ApplyBoolean

If True the value CHECKED is added to the INPUT type=checkbox element – showing a checked checkbox. If False CHECKED is removed, making it unchecked, see forms – What’s the proper value for a checked attribute of an HTML checkbox? – Stack Overflow.


Public Sub ApplyBoolean(Bookmark As String, Value As Variant)

FillElement

Replaces all instances with the bookmark with the string value. This concerns both the visible text and html element attributes.


Public Sub FillElement(Bookmark As String, Value As String)

FillListFromArray

Adds the items in the 1-dimensional array in list item elements <li>


Public Sub FillListFromArray(Bookmark As String, Array1D As Variant)

FillPicture

Sets the source attribute of the <IMG> element with the filepath specified in ImageFile argument. This will replace the dummy image previously set in the template.


Public Sub FillPicture(Bookmark As String, ImageFile As String)

FillPictureFromAttachment

Same as FillPicture, but now obtaining the picture from the Attachment.


Public Sub FillPictureFromAttachment(Bookmark As String, control As Attachment)

FillTableFromArray

Fill Table From Array. Bookmark = Table.Id


Public Sub FillTableFromArray(Bookmark As String, Array2D As Variant, Optional ColumnOrder As String) 

InsertFile

Inserts the contents of another HTML file at the bookmark indicated an <IMG> element. The dummy text file image indicating the location is removed in the process.


Public Sub InsertFile(Bookmark As String, FileName As String)

Load

Loads the template for processing from the specified HTML file


Public Sub Load(ByVal FileName As String)

SaveAs

Save the current HTML to an HTML file.


Sub SaveAs(FileName As String)

Properties

HTML

Gets the HTML Document’s Element outerHTML. Its most common use is for setting the email HTMLBody property.


Property Get HTML() As String