A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Loop through all folders in a mailbox



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 17th 06, 11:24 AM posted to microsoft.public.outlook.program_vba
Bob Smith
external usenet poster
 
Posts: 34
Default Loop through all folders in a mailbox

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  
Old May 17th 06, 01:23 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Loop through all folders in a mailbox

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  
Old May 25th 06, 09:26 PM posted to microsoft.public.outlook.program_vba
Bob Smith
external usenet poster
 
Posts: 34
Default Loop through all folders in a mailbox

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  
Old May 25th 06, 09:58 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Loop through all folders in a mailbox

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  
Old May 25th 06, 11:23 PM posted to microsoft.public.outlook.program_vba
Bob Smith
external usenet poster
 
Posts: 34
Default Loop through all folders in a mailbox

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 02:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.