我想從保存的Outlook消息中提取附件,以便我可以從附加的Excel電子表格中挖掘數據。這些消息已經以.msg文件的形式保存到共享文件夾中,並且我正努力讓VBA甚至將這些消息識別爲文件。我最初試圖在下面的代碼中獲取消息細節作爲概念證明。試圖從保存的.msg文件使用VBA提取Outlook附件
一旦我有這個工作,我可以通過循環處理文件和處理附件。我在該網站上發現了很多代碼,用於從仍在Outlook中的電子郵件中提取附件,但我無法訪問Outlook文件夾並且原始郵件已被刪除。
Sub ExtractExcel()
Dim aExcel As Outlook.Attachment
Dim stFilePath As String
Dim stFileName As String
Dim stAttName As String
Dim stSaveFolder As String
Dim oEmail As Outlook.MailItem
'~~> Outlook Variables for email
Dim eSender As String, dtRecvd As String, dtSent As String
Dim sSubj As String, sMsg As String
stFilePath = "Y:\Purchasing\The Team\User Name\Supply Chain Admin - Outlook\New-Revised Orders\FW Mail Order Daffodil.msg"
stSaveFolder = "C:\Projects\SOTD\PO_Excel"
Debug.Print stFilePath
Debug.Print stSaveFolder
oEmail = stFilePath
With oEmail
eSender = oEmail.SenderEmailAddress
dtRecvd = oEmail.ReceivedTime
dtSent = oEmail.CreationTime
sSubj = oEmail.Subject
sMsg = oEmail.Body
Debug.Print eSender
Debug.Print dtRecvd
Debug.Print dtSent
Debug.Print sSubj
Debug.Print sMsg
End With
End Sub
我使用Excel VBA,因爲我很熟悉它,但很高興有任何其他策略建議。任何和所有的指針感激地收到。
感謝
凱爾
你看過CreateItemFromTemplate從http://stackoverflow.com/questions/7890612/vba-code-to-save-an-attachment-excel-file-from-an-outlook-email-that-was-insid/7916444#7916444? – brettdj