mydesireduse
02-15-2007, 02:25 PM
First, I'm a complete noob to VBA. Didn't know what it stood for until recently. Im comfortable with C/C++ and Java, little php & perl, so I'm not a new programmer.
Found a great snippet of code here that I've slightly modified.(I'd link to original but forum software forbids based on noobie status)
'########################################################################## #####
'### Module level Declarations
'expose the items in the target folder to events
Option Explicit
Dim WithEvents TargetFolderItems As Items
'set the string constant for the path to save attachments
Const FILE_PATH As String = "C:\schedules\"
'########################################################################## #####
'### this is the Application_Startup event code in the ThisOutlookSession module
Private Sub Application_Startup()
'some startup code to set our "event-sensitive" items collection
Dim ns As Outlook.NameSpace
'
Set ns = Application.GetNamespace("MAPI")
Set TargetFolderItems = ns.Folders.Item( _
"Personal Folders").Folders.Item("Schedules").Items
End Sub
'########################################################################## #####
'### this is the ItemAdd event code
Sub TargetFolderItems_ItemAdd(ByVal Item As Object)
'when a new item is added to our "watched folder" we can process it
Dim olAtt As Attachment
Dim i As Integer
Dim retVal As Variant
If Item.Attachments.Count > 0 Then
For i = 1 To Item.Attachments.Count
Set olAtt = Item.Attachments(i)
'save the attachment
olAtt.SaveAsFile FILE_PATH & olAtt.FileName
Next
End If
Set olAtt = Nothing
retVal = Shell("C:\schedules\winscp3.exe /script=C:\schedules\winscp.txt", vbNormalFocus)
End Sub
'########################################################################## #####
'### this is the Application_Quit event code in the ThisOutlookSession module
Private Sub Application_Quit()
Dim ns As Outlook.NameSpace
Set TargetFolderItems = Nothing
Set ns = Nothing
End Sub
Anytime a message is manually dropped into the "Schedules" folder, this code automatically saves the attachments into "C:\schedules" After saving the attachments, I call WINSCP which runs a script that scp's the attachments over to a unix box.
HOWEVER, whenever I add a rule to automatically move a message from INBOX to schedules(based on sender and subject), this code does not run. It only activates on a manual add, not on a rule message move.
How can I modify this code so that it will detect incoming message moves into the Schedules folder and take the appropriate action??
I don't care if its a VBA-only solution, a rule, custom action, etc --- just so it works in Outlook 2003.
Thanks.
Keith
Found a great snippet of code here that I've slightly modified.(I'd link to original but forum software forbids based on noobie status)
'########################################################################## #####
'### Module level Declarations
'expose the items in the target folder to events
Option Explicit
Dim WithEvents TargetFolderItems As Items
'set the string constant for the path to save attachments
Const FILE_PATH As String = "C:\schedules\"
'########################################################################## #####
'### this is the Application_Startup event code in the ThisOutlookSession module
Private Sub Application_Startup()
'some startup code to set our "event-sensitive" items collection
Dim ns As Outlook.NameSpace
'
Set ns = Application.GetNamespace("MAPI")
Set TargetFolderItems = ns.Folders.Item( _
"Personal Folders").Folders.Item("Schedules").Items
End Sub
'########################################################################## #####
'### this is the ItemAdd event code
Sub TargetFolderItems_ItemAdd(ByVal Item As Object)
'when a new item is added to our "watched folder" we can process it
Dim olAtt As Attachment
Dim i As Integer
Dim retVal As Variant
If Item.Attachments.Count > 0 Then
For i = 1 To Item.Attachments.Count
Set olAtt = Item.Attachments(i)
'save the attachment
olAtt.SaveAsFile FILE_PATH & olAtt.FileName
Next
End If
Set olAtt = Nothing
retVal = Shell("C:\schedules\winscp3.exe /script=C:\schedules\winscp.txt", vbNormalFocus)
End Sub
'########################################################################## #####
'### this is the Application_Quit event code in the ThisOutlookSession module
Private Sub Application_Quit()
Dim ns As Outlook.NameSpace
Set TargetFolderItems = Nothing
Set ns = Nothing
End Sub
Anytime a message is manually dropped into the "Schedules" folder, this code automatically saves the attachments into "C:\schedules" After saving the attachments, I call WINSCP which runs a script that scp's the attachments over to a unix box.
HOWEVER, whenever I add a rule to automatically move a message from INBOX to schedules(based on sender and subject), this code does not run. It only activates on a manual add, not on a rule message move.
How can I modify this code so that it will detect incoming message moves into the Schedules folder and take the appropriate action??
I don't care if its a VBA-only solution, a rule, custom action, etc --- just so it works in Outlook 2003.
Thanks.
Keith