我收到运行时错误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
答案 0 :(得分:1)
首先,我建议从MSDN中的Getting Started with VBA in Outlook 2010文章开始。
您需要按如下方式更改每个循环:
'~~> 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方法从包含该项目的文件夹中删除该项目。