我想从保存的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