Does anyone know how to programaticaly detach an attachment please

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my application I need to be able to monitor a folder (not the inbox

When a email is moved to that folder with an attachment I want to save the attachment to a fixed location and then delete the email

I can find loads of examples of how to make a document and attach a file but can't find how to make it go the other way

Any help would be very much appreciated
 
In my application I need to be able to monitor a folder (not the
inbox)

When a email is moved to that folder with an attachment I want to save
the attachment to a fixed location and then delete the email.

I can find loads of examples of how to make a document and attach a
file but can't find how to make it go the other way.

Any help would be very much appreciated



My very first Macro did something similar to this. Since it is my only
macro to date, I have to admit that I'm not an expert, but I'll try to
answer your question to the best of my ability.


I think if you take a look at the 2002 Outlook Object model (take a look
at pdf linked to http://www.microeye.com/resources/ObjectModel2002.htm)
and work your way backwards, you'll find that an Attachment object and
all its methods (SaveAsFile) belongs to the Attachments collection
property of an Item object, which itself belongs to the Items
collection.


The Items collection property belongs to the MAPIFolder object, which
can be instantiated by several methods from the NameSpace object
(GetFolderFromID or PickFolder might be suitable for you).


The NameSpace object is instantiated from the Application object.


So in pseudocode, it might look something like this:


Get Outlook Application Object
Get Namespace Object From Outlook Application Object
Get MAPIFolder object from Namespace Object -- Pointing to your folder

For each Item in the Items Collection From the MAPIFolder object
For each Attachment in the Attachments collection from Item object
Save Attachment to "insert path"
Next
Delete Item
Next


I think in both loops you have to count down because every time you
delete something from a collection the index gets reset and if you don't
count down, you can skip around in the object. At least that's what
I've learned from Sue Mosher. :)
 
You haven't mentioned how you actually plan to implement this...is this in
Exchange environment? What version of Outlook?

Nevertheless, something like this...

Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.Folders("SOME FOLDER")
Set myItem = myFolder.Items(1)
Set myAttachment = myItem.Attachment

myAttachment.SaveAsFile "PATH TO DOCUMENT HERE"

myItem.Delete


--
Paul Overway
Logico Solutions, LLC
www.logico-solutions.com


Peter Bulmer said:
In my application I need to be able to monitor a folder (not the inbox)

When a email is moved to that folder with an attachment I want to save the
attachment to a fixed location and then delete the email.
I can find loads of examples of how to make a document and attach a file
but can't find how to make it go the other way.
 
Back
Top