Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2014, 06:44 AM
gbaker gbaker is offline VBA code Save As Windows 7 32bit VBA code Save As Office 2010 32bit
Competent Performer
VBA code Save As
 
Join Date: May 2012
Posts: 111
gbaker is on a distinguished road
Default VBA code Save As

Hi All,
I would like to create a macro in Outlook that will take an attachment in an e-mail and save it to a folder on the company network. Is there a code that would accomplish this.
Now when an e-mail comes in with the attachment I right click on the attachment, do save as and put it in the correct folder on the company network.
Any Ideas!!!
Thanks GWB
Reply With Quote
  #2  
Old 07-03-2014, 05:19 PM
niton niton is offline VBA code Save As Windows 7 64bit VBA code Save As Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

Select one or more mailitems. Be aware files with the same name are overwritten without any warning.

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 = "H:\test"
If (Dir$(StrFolderPath, vbDirectory) = "") Then
    Debug.Print "'" & StrFolderPath & "' not exist"
    MkDir StrFolderPath
    Debug.Print "'" & StrFolderPath & "' we create it"
Else
    Debug.Print "'" & 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 = "Attachments Have Been saved to " & StrFolderPath & vbCr & vbCr
msg = msg & "ItemsCount : " & ItemsCount & vbCr & vbCr
msg = msg & "ItemsAttachmentsCount : " & ItemsAttachmentsCount
MsgBox msg
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code Save As When I try to save an existing word doc, save as pops up and will not save... samanthab Word 3 01-19-2013 06:27 AM
Word ask to save template whenever i save a derived document jorbjo Word 3 10-04-2012 10:52 AM
VBA code Save As VBA Code to force 'Save As' rossi45 Excel Programming 1 05-11-2012 03:05 PM
VBA code Save As Code to stop as "save as" if the mail merge has not been done tonywatsonmail Mail Merge 4 04-27-2012 01:57 AM
VBA code Save As 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 04:31 PM.


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