• Home
  • About
  • Downloadables
  • Weightloss for Recessive Times

Kibo …

… keeping meat fresh since 1970

Feed on
Posts
Comments

Save & Delete Attachments

May 18th, 2005 by Intermanaut

This macro for Outlook 2002 will traverse every folder in your “Inbox” and then save any attachments to a location you speficy, mirroring the structure of your Inbox. Once saved, the attachments are removed from the email message. A note is added to the top of affected messages to indicate where the attachment has been saved.

NOTE: This macro will remove all attachments from your email messages.

Dim AttachmentStore As String

 

Sub SaveAttachments()

Dim oApp As Application

Dim oNS As NameSpace

Dim oMsg As Object

Dim oAttachments As Outlook.Attachments

Set oApp = New Outlook.Application

Set oNS = oApp.GetNamespace(”MAPI”)

 

‘ Set the following variable to specify the target location

AttachmentStore = “C:\Data\EMail Attachments\”

ProcessFolder oNS.GetDefaultFolder(olFolderInbox)

End Sub

 

Sub ProcessFolder(CurrentFolder As Outlook.MAPIFolder)

Dim i As Long

Dim olNewFolder As Outlook.MAPIFolder

Dim olTempItem As Object

If Replace(CurrentFolder.FolderPath, “\\Personal Folders\Inbox”, “”) <> “” Then

On Error Resume Next

MkDir AttachmentStore & Replace(CurrentFolder.FolderPath, “\\Personal Folders\Inbox”, “”)

End If

For Each oMsg In CurrentFolder.Items

With oMsg

If .Attachments.Count > 0 Then

AttachmentInfo = “”

For x = .Attachments.Count To 1 Step -1

.Attachments.Item(x).SaveAsFile AttachmentStore & Replace(CurrentFolder.FolderPath, “\\Personal Folders\Inbox”, “”) & “\” & .Attachments.Item(x).FileName

AttachmentInfo = AttachmentInfo & “Attachment saved to: ” & AttachmentStore & “\” & Replace(CurrentFolder.FolderPath, “\\Personal Folders\Inbox”, “”) & “\” & .Attachments.Item(x).FileName & vbCrLf

 

‘ Comment this line for testing

.Attachments.Remove x

.Save

Next

.Body = AttachmentInfo & “—–” & vbCrLf & vbCrLf & .Body

.Save

End If

End With

Next

 

For Each olNewFolder In CurrentFolder.Folders

If olNewFolder.Name <> “Deleted Items” Then

ProcessFolder olNewFolder

End If

Next

End Sub

Posted in VBA | No Comments

Comments are closed.

  • Recent Posts

    • Kids & Boredom
    • Robin Hood
    • Why should Facebook be responsible for what your kids do on-line?
    • Hot Tub Time Machine
    • Data Back-up and The Cloud
  • Things

    • About
    • Addresses worth banning from your forum
    • Downloadables
    • Foamcore Macro Studio
    • Multiplicity: Pouring yourself a beer
    • Multiplicity: The five of me
    • Ross on Wye: What a Mess
    • Weightloss for Recessive Times
  • Stuff

    • Conversations (22)
    • Movies (15)
    • Programming (12)
      • ASP (3)
      • JavaScript (6)
      • PHP (2)
      • VBA (1)
    • Rambles (262)
      • Angry (47)
      • Happy (21)
    • Blogroll

      • 1 city, 2 people, 24 hours
      • del.icio.us
      • EmmieJay - guilt-free style
      • flickr

Kibo … © 2010 All Rights Reserved.

MistyLook made free by Web Hosting Bluebook