我正在使用 VBA 發送帶有文本附件的電子郵件。到目前為止,我需要在磁盤上物理創建檔案,然后參考其路徑。
這可以完全在記憶體中完成嗎?
Dim outlook As Object, mail As Object, path As string
Set outlook = CreateObject("Outlook.Application")
Set mail = outlook.CreateItem(0)
' write file contents
path = Environ("temp") "\file.txt"
Open path For Output As #1
Print #1, "This is my txt"
Close #1
' attach file
With mail
.To = "[email protected]"
.body = "This is a test"
.attachments.Add CStr(path)
.send
End With
Set mail = Nothing
Set outlook = Nothing
uj5u.com熱心網友回復:
Outlook 物件模型不為此提供任何屬性或方法。類的Add方法Attachments只接受檔案路徑。更準確地說,附件的來源可以是檔案(由帶有檔案名的完整檔案系統路徑表示)或構成附件的 Outlook 專案。
但是,您可以使用低級 API - 構建 Outlook 的擴展 MAPI。或者考慮圍繞此 API 的任何第三方包裝器,例如 Redemption。在PR_ATTACH_DATA_BIN包含通常是通過物件鏈接和嵌入(OLE)進行訪問二進制附件資料IStream介面。當PR_ATTACH_METHOD( PidTagAttachMethod) 屬性的值為 時,該屬性持有附件ATTACH_BY_VALUE,這是通常的附件方法,也是唯一需要支持的方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/370744.html
