0
我正在使用以下代碼將附件從電子郵件保存到文件夾中,現在我想添加一個if條款或條件,該條款只保存具有.pdf擴展名的附件。VBA使用pdf擴展名保存電子郵件附件到文件夾
是否有人可以告訴我怎麼可以改變我的代碼來獲得這種情況發生,在此先感謝
Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
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
' Get the path to your My Documents folder
On Error Resume Next
' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection
' The attachment folder needs to exist
' You can change this to another folder name of your choice
' Set the Attachment folder.
strFolderpath = "\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\TEST\"
' Check each selected item for attachments.
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
' Use a count down loop for removing items
' from a collection. Otherwise, the loop counter gets
' confused and only every other item is removed.
For i = lngCount To 1 Step -1
' Get the file name.
strFile = objAttachments.Item(i).FileName
' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile
Next i
End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
感謝,但這樣做你知道我的代碼在哪裏,我會把這個,因爲我繼續得到一個編譯錯誤,而不是 – 2014-10-01 12:44:02
你應該堅持這個你r'For Each objMsg ...'循環 – JNevill 2014-10-01 12:48:07
即時通訊但是stile出現編譯錯誤 – 2014-10-01 12:50:46