Chris,
In fact what you want to do is not that complicated. It's long, and you need to keep track of where you are, but VBA is very friendly when it comes to its own objects.
I've developed a similar system for automating the processing of incoming mail. You can do it so that Outlook automatically checks the Inbox, but that's a bit harder, and is not very reliable. The current method initiates a macro by way of a toolbar button, and isn't bad, if a bit flaky at times (but that's Outlook - we can only work with the tools we have).
Stage 1 is to add the references you'll need to be able to access the Excel/Word object models. In the "Visual Basic Editor" (Alt+F11, or Tools/Macros/Visual Basic Editor), select Tools/References, and find the "Microsoft Excel x.x Object Library", and/or the "Microsoft Word x.x Object Library". Select the models you need, and apply these preferences.
Stage 2 is to establish a "path" to the Inbox. This code has to be placed in "This Outlook Session" in "Microsoft Outlook Objects".
Code:
Dim intLoop as Integer
Dim oNameSpace As NameSpace
Dim oInboxItems As Items
Dim oMailItem As MailItem
Dim oAttachments as Attachments
Dim oAttachment as Attachment
Dim oDestinationFolder as MAPIFolder
Dim oExcel as Excel.Application
Dim oWord as Word.Application
Set oNameSpace = Application.GetNamespace("MAPI")
' Instantiate the Items collection for the folder to monitor ...
Set oInboxItems = _
oNameSpace.GetDefaultFolder(olFolderInbox).Items
For Each oMailItem In oInboxItems
With oMailItem
Set oAttachments = .Attachments
If oAttachments.Count <> 0 Then
for intLoop = 1 to oAttachments.Count
set oAttachment = oAttachments(intloop)
' Find out here if the extension of ".FileName" = "xls" or "doc"
' You can code this bit ...
If "extension = xls" Then
set oExcel = New Excel.Application
oExcel.Workbooks.open .Filename
if oExcel.range("A1") = "???" then
Set oProcessed = _
objNameSpace.GetDefaultFolder(olFolderInbox). _
Folders.Item("xls"). _
Folders.Item("???")
.UnRead = False ' Looks neater
.MoveItem oProcessed
End If
End If
Next
End If
End With
Next
You'll of course want to tidy this up a bit - I've kind of been making it up as I go along, so it's a bit messy. And of course, set all your objects to "Nothing" when you've finshed with them - not only stops memory leaks, but results can be a bit unpredicatble with objects left lying around in memory.
Lastly, you may want to shift some of the processing off into functions or subroutines to make your "mainline" a bit easier to follow. I've in fact cobbled this single piece of code together from a couple of different subroutines.
This won't be the final solution, by any means, but I hope it gives you somewhere to start.
Best regards,
SmallCraig
![[upsidedown] [upsidedown] [upsidedown]](/data/assets/smilies/upsidedown.gif)