Sub newEmailWithTable()
Dim olApp As Outlook.Application
Dim olMessage As Outlook.MailItem
Dim strHtmlTable As String
Dim i As Integer
Dim j As Integer
Dim intCols As Integer
Dim intRows As Integer
Dim strSubject As String
Dim strColHeader As String
' Setting variables
' These variables can be passed as macro variables
' by setting the sub routine to include them
' this way the macro can be reused
intCols = 4
intRows = 10
strSubject = "Subject goes here"
strColHeader = "Test"
' Create Outlook session
Set olApp = New Outlook.Application
' Create new Outlook mail item
Set olMessage = olApp.CreateItem(olMailItem)
With olMessage
.Subject = strSubject
' Start building HTML code
' Style properties can be defined here
' Look at the existing CSS properties for table, th, and td elements
strHtmlTable = "<html>" & _
"<head>" & _
" <style>" & _
" table {border: 1px solid #ccc;}" & _
" td, th {border: 1px solid #ccc;width: 100px; height: 20px;padding: 0px}" & _
" </style>" & _
"</head>" & _
"<body>" & _
" <table cellspacing=""0"" cellpadding=""0"">" & _
" <thead>" & _
" <tr>"
' Set up column headers
For j = 1 To intCols
strHtmlTable = strHtmlTable & _
" <th>" & strColHeader & j & "</th>"
Next j
' End of table head, thead, element
strHtmlTable = strHtmlTable & _
" </tr>" & _
" </thead>"
' Table rows
For i = 1 To intRows
strHtmlTable = strHtmlTable & "<tr>"
' Table columns
For j = 1 To intCols
strHtmlTable = strHtmlTable & "<td></td>"
Next j
strHtmlTable = strHtmlTable & "</tr>"
Next i
' Finalize table
strHtmlTable = strHtmlTable & _
" </table>" & _
"</body>" & _
"</html>"
' Set the HTMLBody property of the mail item
.HTMLBody = strHtmlTable
' Display the message window
.Display
End With
End Sub