PDA

View Full Version : Outlook 2000: Automated Save Attachments Macro



Russtar
11-20-2008, 12:20 AM
Hi,

Really could do with your assistance in devising the following macro gents within Outlook 2000.

I need a macro that runs every time a new mail arrives in a certain subfolder that then extracts an attached pdf file and then saves it in a folder on the hd of the local machine. Finally it would be great if after doing so it would move the mail to deleted items.

Another thing to be conscious of is that I don't want any message/errors appearing on screen to advise that the macro has been successful or otherwise.

I don't ask a lot do I Is this possible?

Thanks,

Russ

GTO
11-25-2008, 12:19 AM
I don't ask a lot do I Is this possible?

Greetings Russ,

I see you just joined the forum. Welcome:) , you will meet some very nice folks here.

Now as to your questions, Yes, and I think 'sorta'.

Okay, sorry, I just couldn't resist the first. As to the 'sorta', I am certainly not the one to ask reference Outlook, as I've barely had cause to touch it (vba-wise). That said, I see your thread is languishing, so let me see if I can help at all.

I am currently on Outlook 2003, but could probably access 2000 if I needed to. I don't believe too awful much (leastwise that would effect this question) has changed, so here goes.

There is an Application Event that will fire whenever something lands in the In Box. I do not know of any events relating to an incoming email being moved by the app (I assume you have a Rule in place that moves these msgs to the subfolder).

There is an Event that appears to run at StartUp, so presuming it does what I figure it must, would it be okay that your subfolder is checked when you start Outlook?

Finally, do you have any code thus far?

Mark

JP2112
12-04-2008, 06:46 AM
I have some sample code here you could adapt:

http://www.codeforexcelandoutlook.com/blog/2008/09/hold-that-email/

For example, the following code placed in the ThisOutlookSession module will monitor the default Inbox for new mail items. When a new message is received (or placed in the Inbox), the attachment is saved to the desktop and the message is deleted. I didn't test the code so you probably want to test it first. You didn't provide enough detail so if the emails have multiple attachments, you'll need to add additional code that checks the file extension for "pdf" before saving.



Private WithEvents MyItems As Outlook.Items


Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
Set MyItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub


Private Sub MyItems_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
Dim Msg As Outlook.MailItem
Dim FileN As String
Set Msg = Item
FileN = Msg.Attachments.Item(1).DisplayName
Msg.Attachments.Item(1).SaveAsFile Environ("userprofile") & "\Desktop\" & FileN
Msg.Delete
End If
End Sub



Hi,

Really could do with your assistance in devising the following macro gents within Outlook 2000.

I need a macro that runs every time a new mail arrives in a certain subfolder that then extracts an attached pdf file and then saves it in a folder on the hd of the local machine. Finally it would be great if after doing so it would move the mail to deleted items.

Another thing to be conscious of is that I don't want any message/errors appearing on screen to advise that the macro has been successful or otherwise.

I don't ask a lot do I Is this possible?

Thanks,

Russ