Consulting

Results 1 to 2 of 2

Thread: Sedn Word document with html to Outlook as body of message

  1. #1

    Sedn Word document with html to Outlook as body of message

    I am working within Access 2010 and using VBA to merge fields to Word template with bookmarks to create the body of email messages to multiple people. I send the word template to Outlook to be used as the body of the message, and then send them. I have that working fine.

    Now I have a Word template that contains HTML links and I must send the letter as the body of Outlook email message to send to multiple people. For some reason, it loses all the formatting of the Word document when it gets to Outlook. All the paragraphs run together and the text which is HTML doesn't appear to be HTML. I don't know what I am omitting or doing wrong. Can someone help me?

    Here is the code in my MS Access database............



    Dim rs As Recordset
    Dim vRecipientList As String
    Dim vMsg As String
    Dim vSubject As String
    Dim MailItem As Outlook.MailItem
    Dim strFrom As String
    Dim emailto As String
    Dim emlbodyfrmword As String
    Dim AddyLineVar As String
    Dim Salutation As String
    Dim Wrd As New Word.Application
    Dim MergeDoc As String
    Dim Res As String

    DoCmd.RunMacro "BULK_STDNT_EMAIL"

    'Prepare Outlook for emailing
    BulkInitOutlook
    'Run Access query to get data
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM STDNTS_NO_LETTER")

    If rs.RecordCount > 0 Then
    rs.MoveFirst
    Do
    If Not IsNull(rs!Email) Then

    ' merge fields to Word template
    'Declare an instance of Microsoft Word
    Set Wrd = CreateObject("Word.Application")
    'specify the path and name to the word document
    MergeDoc = "C:\users\dbeville\desktop\Applicant Welcome Letter.dotx"
    'open the document template, make it visible
    Wrd.Documents.Add MergeDoc
    Wrd.Visible = True


    If (rs![RESIDENCY] = "IS") Then
    Res = "In State"
    Else
    Res = "Out of State"
    End If


    'replace each bookmark with current data
    With Wrd.ActiveDocument.Bookmarks


    .item("firstname").Range.Text = rs![FirstName]
    .item("email").Range.Text = rs![Email]
    .item("plandesc").Range.Text = rs![plandesc]
    .item("emplid").Range.Text = rs![EMPLID]
    .item("term_desc").Range.Text = rs![TERMDESC]
    .item("residency").Range.Text = rs![RESIDENCY]
    .item("resdesc").Range.Text = rs![resdesc]
    End With


    'Use content of Word document for body of eMail message and send

    Set MailItem = outlookApp.CreateItem(olMailItem)


    MailItem.BodyFormat = olFormatHTML
    MailItem.TO = rs![Email]
    MailItem.SUBJECT = Me![txtSUBJECT]
    MailItem.HTMLBody = Wrd.ActiveDocument.Content
    MailItem.send


    'append email record to student email history table
    txtEMPLID = rs![EMPLID]
    txtRes = Res
    txtFromName = "Mary Lee Walsh"
    txtAppl_date = rs![APPL_DATE]
    DoCmd.RunMacro "APP_STDNT_BULK_EMAIL_HIST"

    Set MailItem = Nothing
    rs.MoveNext
    Else
    rs.MoveNext
    End If

    Loop Until rs.EOF

    DoCmd.RunMacro "EMAIL_SENT_MSG"
    BulkCleanUp
    Wrd.Quit
    End If

    DoCmd.CLOSE


    End Sub

  2. #2
    try
    MailItem.Body = Wrd.ActiveDocument.Content

    if that does not help, then maybe you should convert the word doc to html first, else set the editor type to word

Tags for this Thread

Posting Permissions

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