Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2013, 09:10 PM
niton niton is offline Save attachments to defined path via VBA Windows 7 64bit Save attachments to defined path via VBA Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default


Try this

Code:
 
Private Sub SaveAttachments_Selection()
Dim Item As Object
Dim ItemAttachment As Object
Dim StrFolderPath As String
Dim strFileName As String
Dim ItemsCount As Long
Dim ItemsAttachmentsCount As Long
Dim iSave As Long
Dim msg As String
StrFolderPath = "C:\test\"
If (Dir$(StrFolderPath, vbDirectory) = "") Then
    MsgBox "'" & StrFolderPath & "' not exist"
    MkDir StrFolderPath
    MsgBox "'" & StrFolderPath & "' we create it"
Else
    MsgBox "'" & StrFolderPath & "' exist"
End If
If Right(StrFolderPath, 1) <> "\" Then
   StrFolderPath = StrFolderPath & "\"
End If
ItemsCount = 0
ItemsAttachmentsCount = 0
 
For iSave = 1 To ActiveExplorer.Selection.Count
 
    Set Item = ActiveExplorer.Selection(iSave)
 
    If TypeOf Item Is MailItem Or TypeOf Item Is PostItem Then
        ItemsCount = ItemsCount + 1
        For Each ItemAttachment In Item.Attachments
            ItemsAttachmentsCount = ItemsAttachmentsCount + 1
            ' Get the file name.
            strFileName = ItemAttachment.FileName
            ' Combine with the path to the Attachments folder.
            strFileName = StrFolderPath & ItemsAttachmentsCount & "_" & strFileName
            ' Save the attachment as a file.
            ItemAttachment.SaveAsFile strFileName
        Next ItemAttachment
 
    End If
 
Next
ExitSub:
Set Item = Nothing
msg = "All Selected Folder Attachments Have Been Downloaded ..." & vbCr & vbCr
msg = msg & "ItemsCount : " & ItemsCount & vbCr & vbCr
msg = msg & "ItemsAttachmentsCount : " & ItemsAttachmentsCount
MsgBox msg
End Sub


******************
Consider rating the thread by going to the "Rate Thread" dropdown.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Save attachments to defined path via VBA FileSystemObject Compile Error: User-Defined Type Not Defined gsrikanth Excel Programming 2 03-28-2022 06:32 AM
Save attachments to defined path via VBA Range.Information(wdStartOfRangeRowNumber): Application-defined or Object-defined err tinfanide Excel Programming 2 06-09-2012 10:19 AM
Save attachments to defined path via VBA Application-defined or Object-defined error Manit Excel Programming 4 12-08-2011 07:35 PM
Outlook 2007 prompts to save opened attachments OfficeAppentice Outlook 0 11-03-2011 09:24 AM
Save attachments to defined path via VBA code to save / rename / send attachments unit213 Outlook 1 09-26-2007 08:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2026 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft