Solved

Need a Module to automatically detach all attachments to a named drive

Posted on 2002-04-24
5
436 Views
Last Modified: 2006-11-17
In Outlook I have an email accountwhere i receive file attachments from various people in the organization.  What i would like to do is to is for ANY incoming email to my folder have a procedure that will run and Detach ALL attachments within the email to S:\AAGIS\Files

What code would i need for this procedure and where would I put it in outlook so that it could run evry time an email came in?
0
Comment
Question by:quizzer
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
rjcpjc earned 250 total points
ID: 6966065
In Outlook 2000 or higher, you would put the code in VBA from within Outlook (or in a COM add-in, but that's more complicated).

You can use the code found here to strip attachments with a button click:

http://www.slovaktech.com/code_samples.htm#StripAttachments

If you want to do this automatically try something like this code which would go in the Application_NewMail event.

Dim mNS as outlook.Namespace
Dim mFolder as outlook.mapifolder
dim objMsg as object


Set mNS as Application.GetNamespace("MAPI")
Set mFolder = mNS.GetDefaultFolder(olFolderInbox)
Set objMsg = mFolder.Items.GetFirst

            Set objAttachments = objMsg.Attachments
            attCount = objAttachments.Count
            If attCount > 0 Then
                For i = attCount To 1 Step -1
                    tmpFile = objAttachments.Item(i).FileName
                    tmpFile = "S:\AAGIS\Files\" & tmpFile
                    objAttachments.Item(i).SaveAsFile tmpFile
                    objAttachments.Item(i).Delete
                Next i
            objMsg.Save


0
 

Author Comment

by:quizzer
ID: 6966186
Thanks rj!!!!  rj where in Outlook is the Application_NewMail
event?
0
 
LVL 9

Expert Comment

by:rjcpjc
ID: 6966191
Open Outlook and hit ALT-F11.  That will open the VBA editor.  Its in ThisOutlookSession.
0
 

Author Comment

by:quizzer
ID: 6966225
We tried alt f11that and nothing happened.  We have Outlook 98 and we can't get to the VBA Editor
0
 
LVL 9

Expert Comment

by:rjcpjc
ID: 6966231
VBA is only supported in Outlook 2000 and higher (see first line of my initial response).  If you are using Outlook 98 then you cannot write code to do this when mail arrives unless you write an Exchange Event script and install it on the Exchange Server.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SBS 2011 - Exchange - Can't received internal 1 34
How can I export certain sent messages from Outlook 2010 7 47
IMAP storage issue 6 63
Outlook 2016 10 33
Read this checklist to learn more about the 15 things you should never include in an email signature.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question