我試圖通過消息來循環複製多個附件,但沒有成功,我得到13 - 類型不匹配錯誤!循環複製多個outlook附件類型不匹配錯誤
任何建議,將不勝感激。
我的代碼如下,
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
哪一行會引發錯誤? –