问题
I run below script to save Outlook attachment on arrival of email. But I frequently get Run-time error '-2147024864 (80070020), which will always stop the inflow of Outlook email. Please advise how to get rid.
Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Email\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
回答1:
try this code please
it prints the name of each attachment before it saves the attachment
press ctrl-G to see "immediate window" where the printout is sent
check the last file name printed when the program crashes
it may provide some insight
Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Email\"
For Each objAtt In itm.Attachments
debug.print objAtt.DisplayName ' print attachment name to "immediate window"
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Next
Set objAtt = Nothing
End Sub
来源:https://stackoverflow.com/questions/44621280/getting-run-time-error-2147024864-80070020-which-saving-outlook-attachment