Solved

Further Modifications to Outlook Macro to save Attachment to Network Folder

Posted on 2006-11-15
4
388 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Find out what you should include to make the best professional email signature for your organization.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

761 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