Paste range from word in mail body including the format

扶醉桌前 提交于 2020-04-30 08:24:27

问题


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 


回答1:


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



回答2:


.HTMLBody = oRange.FormattedText  & olOldBody  


来源:https://stackoverflow.com/questions/61078368/paste-range-from-word-in-mail-body-including-the-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!