2
我發現了幾個關於如何抓取電子郵件附件的頁面,但並不專門針對我需要的內容。附件中的附件
偶爾我會收到包含其他幾封電子郵件作爲附件的電子郵件,並且每個附加電子郵件都包含我想要放在桌面某處的PDF。
這是據我已經得到了:
If inSubj("TEST_STRING") Then 'One of my functions from earlier in the code
Dim atmt As Attachment
Dim outAtmt As MailItem 'Outter attachment (mail attachment)
Dim inAtmt As Attachment 'Inner attachment (invoice pdf)
Dim path As String: path = "C:\SOME_PATH"
For Each atmt In msg.Attachments 'Cycle through attachments
If atmt.Type = olEmbeddeditem Then 'If attached is a MailItem
Set outAtmt = atmt 'Outter attchment = said MailItem
For Each inAtmt In outAtmt.Attachments 'Cycle through attachments (the invoices)
inAtmt.SaveAsFile (path & inAtmt.FileName) 'Save file
Next inAtmt
End If
Next atmt
End If
注意msg
是MailItem
包含其他電子郵件。
這也是我第一次使用For Each循環,因此可能也是一個問題,但現在我只想獲得讓PDF正確的邏輯。
我認爲這個問題是在於outAtmt
是MailItem
,但我不知道它周圍的其他方式。
所以發生了什麼事?你收到和錯誤? – Sorceri
是的,用Set OutAtmt = atmt。可能是因爲不匹配的類型。 – Samsquatch
使用OpenSharedItem http://stackoverflow.com/questions/18723017/how-can-i-handle-the-attachment-of-an-attachment沒有答案的代碼。使用CreateItemFromTemplate http://stackoverflow.com/questions/7890612/vba-code-to-save-an-attachment-excel-file-from-an-outlook-email-that-was-insid-代碼在答案。 – niton