#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 to force 'Save As' | rossi45 | Excel Programming | 1 | 05-11-2012 03:05 PM |
Code to stop as "save as" if the mail merge has not been done | tonywatsonmail | Mail Merge | 4 | 04-27-2012 01:57 AM |
code to save / rename / send attachments | unit213 | Outlook | 1 | 09-26-2007 08:15 PM |