0
失蹤我寫了一些VBA宏下載我outlook.I的所有附件使用下面的代碼來實現這一目標:附件在Outlook 2010中
Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = strFolderpath & "\Attachments\"
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
strDeletedFiles = ""
If lngCount > 0 Then
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
strFile = strFolderpath & strFile
objAttachments.Item(i).SaveAsFile strFile
objAttachments.Item(i).Delete
If objMsg.BodyFormat <> olFormatHTML Then
strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile _
& ">"
Else
strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" _
& strFile & "'>" & strFile & "</a>"
End If
Next i
If objMsg.BodyFormat <> olFormatHTML Then
objMsg.Body = vbCrLf & "The file(s) were saved to " & strDeletedFiles _
& vbCrLf & objMsg.Body
Else
objMsg.HTMLBody = "<p>" & "The file(s) were saved to " _
& strDeletedFiles & "</p>" & objMsg.HTMLBody
End If
objMsg.Save
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
它成功運行。
但我無法在我的系統中找到該文件夾。我試圖至少打開郵件,但它是說附件已被保存到C:\xxxx.....
文件夾中,這個文件夾實際上並不存在於我的系統中。我需要這些附件,它們非常重要。
有什麼方法可以恢復這些郵件附件。 (我猜,附件已從服務器本身刪除,因爲我的代碼objAttachments.Item(i).Delete
中有一個聲明)。