View Full Version : Outlook folders below "Inbox" not seen in code
macrena
01-30-2003, 06:00 PM
does anyone know how to access subfolders of "Inbox"?
******************* begin code ************************
Set objItems = objFolder.Folders("Inbox").Items.Restrict("[UnRead] = True")
If objItems.Count > 0 Then
'Loop through the UnRead mail and parse them
For Each objMailItem In objItems
sbParseMail objMailItem <--- my subroutine to parse the email
Next objMailItem
End If
******************** end code *************************
this works fine.
but i have subfolders below "Inbox", and the code crashes when i put their names in the quotes.
Outlook isn't looking below the root.
so, how are subfolders of "Inbox" referenced?
(i'll take naming them explicitly, but a way of looping through all subfolders would be better!)
thanks!
Anne Troy
01-31-2003, 04:31 PM
I don't suppose this would help?
http://www.freevbcode.com/ShowCode.Asp?ID=1064
macrena
01-31-2003, 04:55 PM
hi Anne,
thanks very much for looking for me.
i ran that code, and it returns the following:
Calendar
Contacts
Deleted Items
Drafts
Inbox
Journal
Mail_Box <--- my user defined folder
Notes
Outbox
Sent Items
Tasks
it doesn't expose the names of the subfolders of those subfolders.
so, i think that when they say >>"...from an Outlook Parent folder."<< they are referring to the subfolders of "Mailbox Name - John Doe".
also, i did find this piece of bad news...
http://support.microsoft.com/?kbid=294869
which says >>"Unlike other Microsoft Office programs that have “full” object models, such as Microsoft Word and Microsoft Excel, the Outlook object model primarily focuses on items and the folders in which they're contained. This means that while you can manipulate items, forms, and certain aspects of folders, many of the commands or settings that are available through the user interface are not available when programming. The Outlook object model does not parallel the Outlook user interface."<<
so i think i'm out of luck :( but i'll keep looking.
thanks again, Anne!
mac
Anne Troy
01-31-2003, 04:59 PM
And the code looked so "cool", Mac.
:D
I'll keep looking around too.
I did send our friend Neo an email notif.
Let's see if he ducks his head in?
Anne Troy
01-31-2003, 06:47 PM
From Neo:
Function GetMAPIFolder(strName)
Dim objNS
Dim objFolder
Dim objFolders
Dim arrName
Dim I
Dim blnFound
Set objNS = Application.GetNamespace("MAPI")
arrName = Split(strName, "/")
Set objFolders = objNS.Folders
blnFound = False
For I = 0 To UBound(arrName)
For Each objFolder In objFolders
If objFolder.Name = arrName(I) Then
Set objFolders = objFolder.Folders
blnFound = True
Exit For
Else
blnFound = False
End If
Next
If blnFound = False Then
Exit For
End If
Next
If blnFound = True Then
Set GetMAPIFolder = objFolder
End If
Set objNS = Nothing
Set objFolder = Nothing
Set objFolders = Nothing
End Function
In his/hers folder example, if they wanted to get a folder named Harry under Mail_Box -- they would call the above function like this.
Dim strTargetFolder
strTargetFolder = "Personal Folders/Mail_Box/Harry"
Set objFolder = GetMAPIFolder(strTargetFolder)
Set colItems = objFolder.Items
Any help??
macrena
02-19-2003, 04:09 PM
hi Dreamboat,
i have worked with this code and have decided that i'm just plain confused about it's intent. the best that can be accomplished here is to set colItems = objFolder.Items but that does nothing to get at the Items of the subfolders therein.
i will have to study the properties of the Items collection:
Application
Class
Count
IncludeRecurrences
Parent
Session
and i don't understand what is being exposed in colItems.
but, in the mean time, i have learned that objFolders is the list of Folders in the current NameSpace, and the function compares the Names of each Folder to the Split() values in strTargetFolder.
by inserting a messagebox (or Debug.Print) in there, i find that the objFolders.Name values are:
Public Folders
Mailbox - Mac Rena
and the Split() values in strTargetFolder are (in Neo's example)
Personal Folders
Mail_Box
Harry
so if i modify strTargetFolder to "Mailbox - Mac Rena", which will make blnFound = True, what then?
what that accomplishes is setting colItems = objFolder.Items
then, using the following code:
Dim obj
For Each obj In objFolder
Debug.Print obj.Name
Next
i get the values that Neo's code produced..... here they are:
Calendar
Contacts
Deleted Items
Drafts
Inbox
Journal
Mail_Box
Notes
Outbox
Sent Items
Tasks
which, of course, is not what i'm after.
so i will have to study the properties of the Items collection, because i can't determine what Neo's code is giving me.
it doesn't look like it gives me the subfolders of Inbox, but i will have to see if i can determine what colItems is and how to get at the Items therein.
thanks,
mac
Anne Troy
02-20-2003, 03:00 PM
Hi, Mac.
Have you considered trying to contact Sue Mosher?
She's www.slipstick.com and maybe she can help?
I've never tried before and I don't know how friendly most of the MVPs are. I've only tried to contact a few...
LOL--tell her you're affiliated here and we just put a link up for her book. Maybe that'll get your foot in the door.
:D
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.