[英]Download Excel related attachments from Outlook inbox and save it in a specific folder based on date range using VBA?
[英]Download Email from Specific Outlook Folder and Save
我在下面的行中收到運行時錯誤5“無效的過程調用或參數”
Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)
我試過一堆修改代碼。 但是我一直無法使它工作。 我想我在理解每個部分的功能時遇到了一些麻煩。
Sub GetAttachments()
Dim oOlAp As Object, oOlns As Object, oOlInb As Object
Dim oOlItm As Object, SubFolder As Object, oOlAtch As Object
Dim NewFileName As String
Const AttachmentPath As String = "\\dsapc429pfs.pactual.net\homefolder02$\wellsty\Desktop\Testing Email Download"
NewFileName = AttachmentPath & "Work?"
Set oOlAp = GetObject(, "Outlook.Application")
Set oOlns = oOlAp.getnamespace("MAPI")
Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)
Set SubFolder = oOlInb.Folders("Test")
If SubFolder.oOlItm.Count > 0 Then
For Each oOlAtch In oOlItm.attachments
oOlAtch.SaveAsFile NewFileName & oOlAtch.FileName
Exit For
Next
Else: End If
End Sub
首先,我建議從MSDN 中的《 Outlook 2010中的VBA入門》一文開始 。
您需要如下更改每個循環的:
'~~> Store the relevant info in the variables
For Each oOlItm In SpecFolder.Items
eSender = oOlItm.SenderEmailAddress
dtRecvd = oOlItm.ReceivedTime
dtSent = oOlItm.CreationTime
sSubj = oOlItm.Subject
sMsg = oOlItm.Body
For Each att in oOlItm.Attachments
att.SaveAsFile Environ("HOMEPATH") & "\My Documents\" & att.FileName
Next
oOlItm.Delete()
Exit For
Next
您對SaveAsFile方法感興趣,該方法將附件保存到指定的路徑。
Delete方法從包含該項目的文件夾中刪除該項目。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.