’outlook VBA 保存附件问题,运行到☆☆☆处就会出问题,请求高人解答,谢谢~
Sub SaveAttachments() Dim Application As Outlook.Application Dim MyNameSpace As NameSpace Dim myFolder As MAPIFolder Dim iMail As Object Dim path0 As String
path0 = "D:\OutLook附件" On Error GoTo lineN1 If Dir(path0) = "" Then MkDir path0 lineN1:
Dim count1, count2, T As Long count1 = CreateObject("scripting.FileSystemObject").GetFolder(path0).Files.Count
Set Application = New Outlook.Application Set MyNameSpace = Application.GetNamespace("MAPI") 'Set myFolder = MyNameSpace.PickFolder Set myFolder = MyNameSpace.GetDefaultFolder(olFolderInbox)
Dim myT1, myT2, myT3, myT As String For Each iMail In myFolder.Items If iMail.Attachments.Count > 0 Then For i = 1 To iMail.Attachments.Count myT1 = CStr(Format(iMail.SentOn, "yyyymmdd")) myT2 = iMail.SenderName ’用ClickYes软件自动点击确定 myT3 = iMail.Attachments.Item(i).FileName ‘☆☆☆运行到此处出现提示框(如图),on error resume next 和 on error goto 语句均跳不过去,偶尔会提示附件已经被打开,但是关闭杀软等所有可能的软件,还是会弹出如上所示提示框,请求高人解答~谢谢 If myT3 Like "*.doc*" Or myT3 Like "*.xls*" Or _ myT3 Like "*.ppt*" Or myT3 Like "*.pdf" Then myT = path0 & "\" & myT1 & "-" & myT2 & "-" & myT3 If Dir(myT) = "" Then iMail.Attachments.Item(i).SaveAsFile myT End If Next i End If Next iMail
Set iMail = Nothing
Set myFolder = Nothing
Set MyNameSpace = Nothing
Set Application = Nothing
count2 = CreateObject("scripting.FileSystemObject").GetFolder(path0).Files.Count
MsgBox "新增" & count2 - count1 & "个附件!", vbInformation
End Sub
|