我創建了一個子例程,它抓取所有相關的詳細信息和附件,爲我發送自動發送的電子郵件。這裏是我的代碼:使用VBA在Outlook電子郵件中附加文件
Sub Mail_workbook_Outlook_1()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim To1 As String, CC1 As String, BCC1 As String, Title1 As String, Body1 As String, Att1 As String
' Create "Other Distribution - In Email" Emails
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
To1 = Cells(8, 2).Value
CC1 = Cells(8, 3).Value
BCC1 = Cells(8, 4).Value
Title1 = Cells(8, 5).Value
Body1 = Cells(8, 6).Value
Att1 = Cells(8, 7).Value
On Error Resume Next
With OutMail
' BodyFormat command makes the email a rich format message allowing us to place attachments within the body of the email instead of in the attachment header
.BodyFormat = olFormatRichText
.To = To1
.CC = CC1
.BCC = BCC1
.Subject = Title1
.Body = Body1
.Attachments.Add Att1, , 10
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
這工作得很好,在我的電子郵件的主體的末尾插入我的執着。問題是這個特定的行:
.Attachments.Add Att1, , 10
在這段代碼中,「10」應該表示附件的位置。 I.E.這應該表示在我的「Body1」變量的前9個字符之後,而不是第10個字符的附件將被放置在這裏。看到這裏:https://msdn.microsoft.com/en-us/library/office/ff869553.aspx
但是,由於某種原因,無論我在位置選項中輸入什麼數字,它總是會將我的附件放在電子郵件的最後。我需要附件是在幾段中間,所以這是一個問題。任何想法是什麼造成這個?
我應該提到我從工具>參考中選擇了Microsoft Outlook對象庫。
任何幫助,非常感謝!
很抱歉的延遲反應不它仍然會把附件放在電子郵件的末尾,出於某種原因,我試着玩弄位置參數並試着#1-3,35-40,50和100.所有這些都通過附件在電子郵件的最後... – YASPLS
@YASPLS您使用的是什麼版本的Outlook?這已經過Outlook2013的測試,並按照描述的方式運行。 – Cisco
思科,感謝您的幫助。請參閱我的其他帖子。展望2 010,顯然這是一個沒有修復的已知錯誤。 – YASPLS