![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I'm trying to loop through all folders in a mailbox with no luck. I'm using
GetLast which seems to get me to my mailbox (can I always assume this?). This is what I have so far, any help would be appreciated. Sub LoopFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myFolder = myNameSpace.Folders.GetLast While Not myFolder Is Nothing MsgBox myFolder Set myFolder = myFolder.Folders.GetNext '-GetPrevious does not seem to work Wend End Sub |
Ads |
#2
|
|||
|
|||
![]()
The recursive procedure at http://www.outlookcode.com/codedetail.aspx?id=628 shows how to iterate all folders beneath a given starting folder. For a mailbox, you'd use Namespace.GetDefaultFolder to return the Inbox, then use the Parent of the Inbox as the starting folder.
-- 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 "Bob Smith" wrote in message ... I'm trying to loop through all folders in a mailbox with no luck. I'm using GetLast which seems to get me to my mailbox (can I always assume this?). This is what I have so far, any help would be appreciated. Sub LoopFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myFolder = myNameSpace.Folders.GetLast While Not myFolder Is Nothing MsgBox myFolder Set myFolder = myFolder.Folders.GetNext '-GetPrevious does not seem to work Wend End Sub |
#3
|
|||
|
|||
![]()
Thanks for the reply Sue,
I tried the previous folder statement but I get an error code 91. Probably a syntax error. Can you look at the last line and tell me what is should be. Sub getFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Dim myInbox As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) Set MyRoot = myNameSpace.GetDefaultFolder(olFolderInbox) MsgBox myInbox.Folders.GetPrevious End Sub "Sue Mosher [MVP-Outlook]" wrote: The recursive procedure at http://www.outlookcode.com/codedetail.aspx?id=628 shows how to iterate all folders beneath a given starting folder. For a mailbox, you'd use Namespace.GetDefaultFolder to return the Inbox, then use the Parent of the Inbox as the starting folder. -- 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 "Bob Smith" wrote in message ... I'm trying to loop through all folders in a mailbox with no luck. I'm using GetLast which seems to get me to my mailbox (can I always assume this?). This is what I have so far, any help would be appreciated. Sub LoopFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myFolder = myNameSpace.Folders.GetLast While Not myFolder Is Nothing MsgBox myFolder Set myFolder = myFolder.Folders.GetNext '-GetPrevious does not seem to work Wend End Sub |
#4
|
|||
|
|||
![]()
If it returns Nothing, then it means there is no previous folder, which is expected since you haven't used GetNext or GetLast.
Is a particular reason why you didn't try the technique I suggested? -- 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 "Bob Smith" wrote in message ... Thanks for the reply Sue, I tried the previous folder statement but I get an error code 91. Probably a syntax error. Can you look at the last line and tell me what is should be. Sub getFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Dim myInbox As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) Set MyRoot = myNameSpace.GetDefaultFolder(olFolderInbox) MsgBox myInbox.Folders.GetPrevious End Sub "Sue Mosher [MVP-Outlook]" wrote: The recursive procedure at http://www.outlookcode.com/codedetail.aspx?id=628 shows how to iterate all folders beneath a given starting folder. For a mailbox, you'd use Namespace.GetDefaultFolder to return the Inbox, then use the Parent of the Inbox as the starting folder. "Bob Smith" wrote in message ... I'm trying to loop through all folders in a mailbox with no luck. I'm using GetLast which seems to get me to my mailbox (can I always assume this?). This is what I have so far, any help would be appreciated. Sub LoopFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myFolder = myNameSpace.Folders.GetLast While Not myFolder Is Nothing MsgBox myFolder Set myFolder = myFolder.Folders.GetNext '-GetPrevious does not seem to work Wend End Sub |
#5
|
|||
|
|||
![]()
Sure, there is a definate reason why I didn't use your technique... I didn't
read your response properly. I thought you said "Previous" not "Parent". Lost in translation from my outlook to my Visual Basic Editor (new I should have got dual monitors). Sorry, I'm a little new to this VBA programming stuff and I'm unfamiliar with the syntax. Thanks for your help (embarrised), "Sue Mosher [MVP-Outlook]" wrote: If it returns Nothing, then it means there is no previous folder, which is expected since you haven't used GetNext or GetLast. Is a particular reason why you didn't try the technique I suggested? -- 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 "Bob Smith" wrote in message ... Thanks for the reply Sue, I tried the previous folder statement but I get an error code 91. Probably a syntax error. Can you look at the last line and tell me what is should be. Sub getFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Dim myInbox As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) Set MyRoot = myNameSpace.GetDefaultFolder(olFolderInbox) MsgBox myInbox.Folders.GetPrevious End Sub "Sue Mosher [MVP-Outlook]" wrote: The recursive procedure at http://www.outlookcode.com/codedetail.aspx?id=628 shows how to iterate all folders beneath a given starting folder. For a mailbox, you'd use Namespace.GetDefaultFolder to return the Inbox, then use the Parent of the Inbox as the starting folder. "Bob Smith" wrote in message ... I'm trying to loop through all folders in a mailbox with no luck. I'm using GetLast which seems to get me to my mailbox (can I always assume this?). This is what I have so far, any help would be appreciated. Sub LoopFolders() Dim myOlApp As Application Dim myNameSpace As NameSpace Dim myFolder As MAPIFolder Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myFolder = myNameSpace.Folders.GetLast While Not myFolder Is Nothing MsgBox myFolder Set myFolder = myFolder.Folders.GetNext '-GetPrevious does not seem to work Wend End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Exchange Mailbox server prohibit from sending when reach mailbox size limit | Milly Staples [MVP - Outlook] | Outlook - General Queries | 1 | February 24th 06 06:41 PM |
Macro to open, retrieve contents, print, and loop through process | Michelle Marie | Outlook and VBA | 2 | February 24th 06 09:39 AM |
Reverse loop? | yonina | Outlook and VBA | 2 | February 2nd 06 09:10 AM |
Loop through a folder and forward each email to a given address | needsomeoutlookhelp | Outlook and VBA | 1 | February 1st 06 08:03 AM |
How to loop through Outlook tasks in VBA | Rick Williams | Outlook and VBA | 2 | January 25th 06 07:59 PM |