最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excel - Word template as an email body and sending email - Stack Overflow

programmeradmin1浏览0评论

I have several Word files and I want to send them as an email template (one after another) to the partners

I've used the following code:

Dim filePath As String
    filePath = "locally stored file" & partnerName & ".docx"
    wordDoc.SaveAs2 filePath
    
    wordDoc.Content.Copy
    Dim dataObj As Object
    Set dataObj = CreateObject("MSForms.DataObject")
    dataObj.GetFromClipboard
    wordContent = dataObj.GetText(1) 
    wordDoc.Close
    emailAddress = ws.Cells(i + 1, 12).Value
    Set outlookMail = outlookApp.CreateItem(0)
    With outlookMail
        .To = emailAddress
        .Subject = "FY25 Reward results for Q3 FY25: " & partnerName
        .HTMLBody = wordContent
        .Send
    End With
Next i

Here I am not getting an error, but the content is sent as a plain text to the recipient.

In my word template, I've images, tables, links, and other formatted text. I want to send the doc as is. Preserving the formatted nature.

Thanks in advance!

I have several Word files and I want to send them as an email template (one after another) to the partners

I've used the following code:

Dim filePath As String
    filePath = "locally stored file" & partnerName & ".docx"
    wordDoc.SaveAs2 filePath
    
    wordDoc.Content.Copy
    Dim dataObj As Object
    Set dataObj = CreateObject("MSForms.DataObject")
    dataObj.GetFromClipboard
    wordContent = dataObj.GetText(1) 
    wordDoc.Close
    emailAddress = ws.Cells(i + 1, 12).Value
    Set outlookMail = outlookApp.CreateItem(0)
    With outlookMail
        .To = emailAddress
        .Subject = "FY25 Reward results for Q3 FY25: " & partnerName
        .HTMLBody = wordContent
        .Send
    End With
Next i

Here I am not getting an error, but the content is sent as a plain text to the recipient.

In my word template, I've images, tables, links, and other formatted text. I want to send the doc as is. Preserving the formatted nature.

Thanks in advance!

Share Improve this question edited Mar 15 at 17:03 braX 11.8k5 gold badges22 silver badges37 bronze badges asked Mar 15 at 8:00 Shreeuday KasatShreeuday Kasat 34 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

I think your call Clipboard calls are getting plain text out of Word ... but Outlook will need HTML.

This (very old) thread has the same question. Solution there uses VB to save/convert the doc to HTML, then send a copy of that HTML to Outlook. I expect this is the route you will need to go:

https://www.experts-exchange/questions/23606380/Copy-Word-Doc-to-Body-of-Email.html

Ah, same one here, also:
How to send a Word document as body of an email with VBA

发布评论

评论列表(0)

  1. 暂无评论