The call from Visual Basic back into Outlook 2000 can only be accomplished once a reference to Outlook has been added to the VB project (Project menu, References option, “Microsoft Outlook 9.0 Object Library” selected).
Talking to Outlook requires access to the current Explorer (the main Window in Outlook), as well as to the selection within this window. The piece of code below shows the number of items in the selected folder, does a Save As on each of the selected items using the subject as the file name to be used, and then modifies the name of the item in Outlook.
VB Code:
Dim myOlSel As Outlook.Selection
Dim olExp, olCurrentFolder
Dim x As Integer
Set olExp = Outlook.ActiveExplorer
Set olCurrentFolder = olExp.CurrentFolder
MsgBox “Folder “ & olCurrentFolder & _
“ has “ & olCurrentFolder.Items & “ items in it”
Set myOlSel = olExp.Selection
‘ Get the subject, SaveAs the message,
‘ modify the subject in the message, and save the changes
What i am trying to do (no VB required because i am using the vba editor) is On new mail, determain who mail item is from, then if it has attachement of type myAttachemen.mld (my own.. its an expense report) then saves it to temp location, then I need to shell a utility program to run. Then it uses that attachemen to up dates the master database...
I am still working on the method .... but i need to figure out and maybe find a way to trigger an update through the mail programs..
Instead of the second message box (the first message box you will want to comment out as soon as possible!), you can do things with the attachment (like copy it, Save Attachments etc.).
Its supposed to look through every one of your Stores, and every one of your folders. I am sure you could get the default store (where your Inbox is positioned) and the default Inbox (where your mail is delivered) quite easily.
MAPI is the connection. Within this are Stores (mailbox, other shared user mailboxes, .PST files etc.). Within each Store are Folders. Within each Folder are Items and other Folders. You need to get down to the correct level...
Alternatively (if you are still at the testing stage, rather than the actual "right, lets do it"), you could use this to call the original routine:
VB Code:
for each Store in MAPI.FOLDERS
rtn = msgbox ("Look in Store: " & Store & "?", 1)
if rtn <> 2 then
for each folder in STORE.Folders
If Folder = "Inbox" then
msgBox "Looking through the: " & Folder
LookThroughFolder (Folder.ITEMS)
end if
next
end if
next
Don't forget to press "Cancel" on the stores you don't want to search through.
K.. this is becoming very clear.
Thanks for your help JordanChris ..
I am thinking about that last piece of code you posted.
It`s exactly what i am looking for. But i dont thinki you can
pass the Items to that function that accepts a folder collection.
I can see what going on but i dont know how to fix it..
How about some hints....
I am still using VB Script, rather than VB. So you will need to change the number "6" to the normal OLDefaultInbox string. Also you will need to change the search string (at the moment its looking for any attachments that start with a "C"). However, this code does work....
VB Code:
msgbox "Searching Outlook Inbox for certain attachments . . ."
'
' First the sub-routine that looks through a specified folder looking for mail
' items and their attachments
'
SUB LookThroughFolder (thisFolder)
for each myItem in thisFolder
'
' Step through all items in the Folder
'
if myItem.CLASS = "43" then
for each Attachment in myItem.Attachments
'
' For any mail item (class 43) with an attachment, check its name
just because i like to throw my 2 cents in about email automation questions... MS placed restrictions on using VB to send email when using outlook 2000 with service release 1a on it. I also heard that this "feature" is built in to office XP right outta the box..
The routine is expecting a collection of items in the folder; NOT the folder name itself. So instead of calling it with myItms.Parent, just use myItms.
If you want to change the routine to accept a folder name, then the first bit of the routine will need to include the statement (approximately):
ItemsInFolder = FolderName.Items
I have taken your code (the last set that works)
An i am trying to declare all the variables to
get a better understanding of whats going on.
It appears that i will never..
Looking throuhg the examples in help, and your help here,
I have determained that maybe you dont have to declare
them..
Is there a reason for this.. if not, could you rewrite that code with all the variable and object variable declared..
I think that will help me understand..
(would this be considered intence oo programing.?)