[英]Adding .docx as body to Outlook e-mail in VBA
我有這段代碼可用於在Excel中使用vba發送電子郵件。
使用.body而不是.Inspector.WordEditor,我可以准確鍵入我想在電子郵件中輸入的內容,但是我希望電子郵件的文本是Word文檔,其中包含一些圖片和內容。
我將如何處理? 我無法讓.Inspector.WordEditor以我想要的方式工作。 (老實說,這對我根本不起作用)
Sub Test1()
Dim networkstatus As Boolean
If InternetGetConnectedState(0&, 0&) Then
networkstatus = True
Else
networkstatus = False
End If
If Not networkstatus = True Then
Exit Sub
End If
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Test"
.Inspector.WordEditor ("C:\test.docx")
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
清理:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
編輯:我知道您可以使用HTMLBody,但是我不指望我的同事使用它。
而是以附件形式發送
.Attachments.Add("C:\\test.docx")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.