outlook 2000 macro, saving attachments

Posted on 2003-03-04
Medium Priority
Last Modified: 2010-05-01
I want to be able to save the attachments of an email to a default locations, thru one button.

Ive got some code to loop thru all the emails in my inbox, and save (See below) but this isnt what im after.  I need to save just the highlighted on, or be able to choose one.  Ie, get rid of the "For Each oMailItem In oFolder.Items" and change it to a single item.

Set oApp = New Outlook.Application
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
Set oMailItem = oFolder.Items

For Each oMailItem In oFolder.Items
    With oMailItem
        If oMailItem.Attachments.Count > 0 Then
            oMailItem.Attachments.Item(1).SaveAsFile 'Dir1.Path & "\" & oMailItem.Attachments.Item(1).Parent & "~~" & oMailItem.Attachments.Item(1).FileName
        End If
    End With
Next oMailItem

Set oMailItem = Nothing
Set oFolder = Nothing
Set oNameSpace = Nothing
Set oApp = Nothing
Question by:calfboy
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
LVL 14

Accepted Solution

jjardine earned 400 total points
ID: 8064022
you might look at something like this

Count = oApp.ActiveExplorer.Selection.Count
If Count > 0 Then
   For Index = 1 To Count
      do your saving of attachments
      it is recommended to make sure it is of class=olMail
   Next index
End If

Good luck

Author Comment

ID: 8064252
it is recommended to make sure it is of class=olMail

How do I do that? ^^

Author Comment

ID: 8064274
I changed my code to be like this,

For Each oMailItem In oApp.ActiveExplorer.Selection
    If oMailItem.Attachments.Count > 0 Then
        oMailItem.Attachments.Item(1).SaveAsFile "c:\" & oMailItem.Attachments.Item(1).FileName
    End If

Now, ill add a loop for each attachment. (Incase there is more then one.)

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

752 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