我试图遍历消息以复制多个附件,但没有成功,我收到 13 - 类型不匹配错误!!!
任何建议将不胜感激。
我的代码如下,
Private Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
'Only act if it's a MailItem
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
'Set folder to save in.
Dim olDestFldr As Outlook.MAPIFolder
Dim myAttachments As Outlook.Attachments
Dim Att As String
Dim i As Integer
'location to save in. Can be root drive or mapped network drive.
Const attPath As String = "C:\Users\pkshahbazi\Documents\EmailAttachments\"
i = 0
'save attachment
Set myAttachments = item.Attachments
If Msg.Attachments.Count <> 0 Then
For Each myAttachments In Msg.Attachments
Att = myAttachments.item(i).DisplayName
myAttachments.item(i).SaveAsFile attPath & Att
'mark as read
i = i + 1
Next myAttachments
Msg.UnRead = False
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub