How to programmatically save all email attachments in a folder

B

Brian Beck

I have a set of folders in a mailbox in Outlook 2003 that I need to work
with. Specifically, I want to create a procedure that will scan through a
folder and check each email for the following:

-check to see if there is an attachment, or even multiple attachments.
-If there are attachment(s), then it should save them to some specified
folder.
-If there are no attachment(s), then it should go and check the next
email.

Is that something fairly trivial to achieve in Outlook? I have experience
writing VBA scripts for Word and Access, but I haven't delved into
programming much at all for Outlook...any ideas would be greatly
appreciated.
 
K

Ken Slovak - [MVP - Outlook]

Dim oItem As Outlook.MailItem
Dim colItems as Outlook.Items

Set colItems = oFolder.Items
For Each oItem in colItems
If oItem.Attachments.Count > 0 Then
'detach attachments here
End If
Next

That snippet would be passed a MAPIFolder object. For code you can modify to
detach the attachments see
http://www.slovaktech.com/code_samples.htm#StripAttachments. That strips
attachments from items selected in a folder view. It can be modified to have
a specific item passed into it, just remove the For Each objMsg In
objSelection loop and the initial initialization code that sets the Outlook
object (use a global one) and the selection collection and pass in objMsg
into the Sub.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top