Solved

Further Modifications to Outlook Macro to save Attachment to Network Folder

Posted on 2006-11-15
4
389 Views
Last Modified: 2010-04-08
Blue DevilFan provided me with the code below which saves the attachment of the current email message to a network drive.  It works great.  As I was using it I was thinking that it would also be fantastic if I could have a similar macro that when fired processed all emails in the current folder (instead of one at a time).   The folder in question is a public folder.

 Can it be done?


Sub SaveAttachment()
    Dim olkMessage As Outlook.MailItem, _
        olkAttachment As Outlook.Attachment, _
        objFSO As Object, _
        myOrt As String, _
        myPath As String
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    myOrt = "J:\Programming\"
    For Each olkMessage In Application.ActiveExplorer.Selection
        myPath = myOrt & olkMessage.SenderName
        If Not objFSO.FolderExists(myPath) Then
            objFSO.CreateFolder (myPath)
        End If
        myPath = myPath & "\" & Format(olkMessage.SentOn,"MM-DD-YYYY")
       If Not objFSO.FolderExists(myPath) Then
            objFSO.CreateFolder (myPath)
        End If
        myPath = myPath & "\"
        If olkMessage.Attachments.Count > 0 Then
            olkMessage.HTMLBody = olkMessage.HTMLBody & "<br><br><b>Saved Attachments</b><br>"
            For Each olkAttachment In olkMessage.Attachments
                With olkAttachment
                    .SaveAsFile myPath & olkAttachment.FileName
                    olkMessage.HTMLBody = olkMessage.HTMLBody & "<a href=""file://" & myPath & olkAttachment.FileName & """>" & olkAttachment.FileName & "</a><br>"
                    .Delete
                End With
            Next
            olkMessage.Save
        End If
    Next
    Set objFSO = Nothing
    Set olkAttachment = Nothing
    Set olkMessage = Nothing
End Sub
0
Comment
Question by:snyperj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 17947377
This macro will process all the messages selected, not just one message.  You could select whichever messages you want and it'd process them all.  If you want to save yourself the step of selecting messages, then change this line

    For Each olkMessage In Application.ActiveExplorer.Selection

to

    For Each olkMessage In Application.ActiveExplorer.CurrentFolder.Items

Now when you run the macro it will process all messages in whatever folder you have selected.
0
 
LVL 35

Expert Comment

by:mvidas
ID: 17947399
Hi again,

'    For Each olkMessage In Application.ActiveExplorer.Selection
    For Each olkMessage In Application.ActiveExplorer.CurrentFolder.Items

I would recommend you not use the J drive for the network drive and instead use the UNC reference (\\server\folder\etc), in case a user doesn't have that drive mapped or it changes for whatever reason.

Matt
0
 

Author Comment

by:snyperj
ID: 17950545
works awesome- thanks BDF!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17951016
No problem.  Always happy to help out.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
problem with office 365 portal 7 42
exchange 13 42
Search inbox emails for multiple words in Outlook 2010 2 50
Export emails from Outlook 2000 to Thunderbird 8 80
If you don't know how to downgrade, my instructions below should be helpful.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question