Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / November 2003

Tip: Looking for answers? Try searching our database.

Does anyone know how to programaticaly detach an attachment please

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Bulmer - 26 Nov 2003 23:56 GMT
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
Harold Pinter - 27 Nov 2003 05:40 GMT
=?Utf-8?B?UGV0ZXIgQnVsbWVy?= <peter@why-not-relax.co.uk> wrote in
news:0109C842-941D-4821-884F-23E06FEBB64D@microsoft.com:

> In my application I need to be able to monitor a folder (not the
> inbox)
[quoted text clipped - 6 lines]
>
> 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.  :)
Peter - 27 Nov 2003 16:37 GMT
Thank You (as usual it obvious when someone tells you)
Paul Overway - 27 Nov 2003 06:01 GMT
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

> In my application I need to be able to monitor a folder (not the inbox)
>
[quoted text clipped - 3 lines]
>
> Any help would be very much appreciated
Peter - 27 Nov 2003 16:37 GMT
Thank you Paul
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.