Consulting

Results 1 to 3 of 3

Thread: Outlook 2000: Automated Save Attachments Macro

  1. #1
    VBAX Newbie
    Joined
    Nov 2008
    Posts
    1
    Location

    Unhappy Outlook 2000: Automated Save Attachments Macro

    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

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by Russtar
    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

  3. #3
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    I have some sample code here you could adapt:

    http://www.codeforexcelandoutlook.co...ld-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
    Quote Originally Posted by Russtar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •