Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

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

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
quizzer
Asked:
quizzer
  • 3
  • 2
1 Solution
 
rjcpjcCommented:
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
 
quizzerAuthor Commented:
Thanks rj!!!!  rj where in Outlook is the Application_NewMail
event?
0
 
rjcpjcCommented:
Open Outlook and hit ALT-F11.  That will open the VBA editor.  Its in ThisOutlookSession.
0
 
quizzerAuthor Commented:
We tried alt f11that and nothing happened.  We have Outlook 98 and we can't get to the VBA Editor
0
 
rjcpjcCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now