Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Further Modifications to Outlook Macro to save Attachment to Network Folder

Posted on 2006-11-15
4
Medium Priority
?
392 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
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…

664 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