+ Reply to Thread
Results 1 to 2 of 2

Thread: Help me insert a table of data into a body of an email

  1. #1
    Valued Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    501

    Help me insert a table of data into a body of an email

    Hi

    I have a table example

    ID First Name Last Name
    1 Bob Smith
    2 Tom Black
    3 John Turner

    in a workbook how do I get this table into a body on an email

    Ihave the following which goes into a body however i would like it to be in a table format with borders etc.

    Sub TestFile()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim cell As Range
        Dim strbody As String
        
        Application.ScreenUpdating = False
        Set OutApp = CreateObject("Outlook.Application")
        On Error GoTo cleanup
        
        For Each cell In ThisWorkbook.Sheets("mail").Range("h6:h14")
            strbody = strbody & cell.Value & vbNewLine
        Next
        For Each cell In Sheets("mail").Columns("b").Cells.SpecialCells(xlCellTypeConstants)
            If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "yes" Then
                Set OutMail = OutApp.CreateItem(0)
                With OutMail
                    .To = cell.Value
                    .Subject = Sheets("mail").Range("h1").Value
                    .Body = "Hello " & cell.Offset(0, -1).Value & vbNewLine & vbNewLine & strbody
                    'You can add other files also like this
                    '.Attachments.Add ("C:\test.txt")
                    .send  'Or use send
                End With
                Set OutMail = Nothing
            End If
        Next cell
    cleanup:
        Set OutApp = Nothing
        Application.ScreenUpdating = True
    End Sub

  2. #2
    Valued Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    501

    Ron

    I wonder if Ron can help as it is part of his code which I find to be very usefull

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0