Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

outlook 2000 macro, saving attachments

Posted on 2003-03-04
3
Medium Priority
?
163 Views
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
            DoEvents
           
        End If
    End With
Next oMailItem

Set oMailItem = Nothing
Set oFolder = Nothing
Set oNameSpace = Nothing
Set oApp = Nothing
0
Comment
Question by:calfboy
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
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
0
 

Author Comment

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

How do I do that? ^^
0
 

Author Comment

by:calfboy
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
Next

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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, 7 hours left to enroll

564 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