2017-06-20 60 views
0

我有這段代碼可用於在Excel中發送電子郵件。將.docx添加爲VBA中的Outlook電子郵件

使用.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,但我不上我的同事們利用計那。

回答

0

把它作爲附件代替

.Attachments.Add("C:\test.docx")

+0

但我想它進入電子郵件的正文。這是一份時事通訊。 – bub

+0

您將需要將其另存爲HTML,然後Word可以執行此操作。然後將HTML讀入電子郵件正文。但是,請記住,大多數現代電子郵件供應商默認情況下會禁用圖片。 – braX

相關問題