View Single Post
  #3  
Old November 11th 06, 02:25 AM posted to microsoft.public.outlook.program_vba
Andrew
external usenet poster
 
Posts: 95
Default Outlook 2003, Rules and Alerts, Script

Thanks Sue ... apprecite you time.

Better pull your book off the shelf again :-)

Andrew

"Sue Mosher [MVP-Outlook]" wrote:

Your code has a major redundancy: The item that triggered the rule is the objMailItem object passed as an argument. Yet you are instantiating an Outlook.Application object (totally unnecessary) and a Selection object. Instead, your code needs to act on the item that fired the rule.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Andrew" wrote in message ...
Hi,

Let me preface this with that I am at the limit of my knowledge making the
few edits I have to a great script I found elsewhere.

The script copies attachments out of emails into a folder. I have added the
function of giving each file attachment a unique name. It then replaces the
attachments with a link to the new filename.

It will not work because the item needs to be highlighted while it is
running for some reason. Outlook does not highlight new items as they arrive
/ leave so it works manually, but will not work as a rule.

Help greatly appreciated. Here it is.

Public Sub SaveAttachments(objMailItem As MailItem)
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
Dim strFileExt As String

' Set the path to documents folder
strFolderpath = "c:\HomeDrive"

On Error Resume Next

' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection

' Set the Attachment folder.
strFolderpath = strFolderpath & "\OLAttachments\"

'MsgBox strFolderpath

' Check each selected item for attachments.
' If attachments exist, save them to the Temp
' folder and strip them from the item.
For Each objMsg In objSelection
' This code only strips attachments from mail items.



Ads