首页 > 解决方案 > Paste range from word in mail body including the format

问题描述

I'm working on a mail merge macro and I'm trying to copy the text from my word document including the format in the mail body unfortunately it doesn't accept the range.paste function there. Looking forward to any advice.

    Set oWord = CreateObject("Word.Application")

    oWord.Documents.Open FileName:="*\Flightticket.docx", ReadOnly:=True
    Set oDoc = oWord.ActiveDocument
    Set oRange = ActiveDocument.Range(Start:=0)
    oWord.Visible = False
    oRange.Copy

*
*
*
           With oMail
               .To = oContact.Email1Address
               .Subject = Left(oDoc.Name, Len(oDoc.Name) - 5) & " " & mText
               .GetInspector.Activate 'Signatur
               olOldBody = .HTMLBody
               'The content of the document is used as the body for the email
                .HTMLBody = oRange.Paste  & olOldBody               'Here is the error
             End With 

标签: vbaoutlookms-wordpaste

解决方案


I now worked around the problem with adding html code to my word document and included the whole content without copy-paste. This worked out pretty good.

.HTMLBody = oDoc.Content & olOldBody

推荐阅读