Folders & Subfolders

Status
Not open for further replies.
M

Marvin Buzz

I am writing in Visual Basic, not VBA. I can write the code to identify all

of the subfolders in Outlook, but do not know how to program for the

subfolders of the subfolders...subfolders to any possible depth of subfolders.

Any samples or guidance would be very much appreciated.

Thanks in advance.
 
Each Folder in Outlook 2007 or MAPIFolder in earlier versions has a Folders

collection containing all its subfolders. Each subfolder in a Folders

collection has a unique name, so you can return any subfolder with an

expression like this:

myParentFolder.Folders("Name of subfolder")

The code sample at http://www.outlookcode.com/codedetail.aspx?id=628 shows

how to process all the folders below a given starting folder.

Sue Mosher

"Marvin Buzz" <MarvinBuzz> wrote in message

news:545FDB05-36E9-4481-B68E-7942906D4B45@microsoft.com...
> I am writing in Visual Basic, not VBA. I can write the code to identify
> all
> of the subfolders in Outlook, but do not know how to program for the
> subfolders of the subfolders...subfolders to any possible depth of
> subfolders.

> Any samples or guidance would be very much appreciated.

> Thanks in advance.
>
 
You need to write a sub or function that is recursively called by itself.

For example:-

Public Sub ProcessAllFolders()

Dim fld As MAPIFolder

For Each fld In Application.GetNamespace("MAPI").Folders

Call ProcessFolder(fld)

Next fld

End Sub

Public Sub ProcessFolder(ByRef fld As MAPIFolder)

Dim subfld As MAPIFolder

'Do Something here

For Each subfld In fld.Folders

Call ProcessFolder(subfld)

Next subfld

End Sub

Alan Moseley IT Consultancy

http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.

"Marvin Buzz" wrote:


> I am writing in Visual Basic, not VBA. I can write the code to identify all
> of the subfolders in Outlook, but do not know how to program for the
> subfolders of the subfolders...subfolders to any possible depth of subfolders.

> Any samples or guidance would be very much appreciated.

> Thanks in advance.
>
 
I am getting a compiler error that says I cannot define user types.

"Alan Moseley" wrote:


> You need to write a sub or function that is recursively called by itself.
> For example:-

> Public Sub ProcessAllFolders()
> Dim fld As MAPIFolder
> For Each fld In Application.GetNamespace("MAPI").Folders
> Call ProcessFolder(fld)
> Next fld
> End Sub

> Public Sub ProcessFolder(ByRef fld As MAPIFolder)
> Dim subfld As MAPIFolder
> 'Do Something here
> For Each subfld In fld.Folders
> Call ProcessFolder(subfld)
> Next subfld
> End Sub

> > Alan Moseley IT Consultancy
> http://www.amitc.co.uk

> If I have solved your problem, please click Yes below. Thanks.

> "Marvin Buzz" wrote:
>
> > I am writing in Visual Basic, not VBA. I can write the code to identify all
> > of the subfolders in Outlook, but do not know how to program for the
> > subfolders of the subfolders...subfolders to any possible depth of subfolders.
> > Any samples or guidance would be very much appreciated.
> > Thanks in advance.
> >
 
Firstly add a reference to Outlook within your project. Secondly import the

namespace before the beginning of your class, ie:-

Imports Microsoft.Office.Interop.Outlook

Alan Moseley IT Consultancy

http://www.amitc.co.uk

If I have solved your problem, please click Yes below. Thanks.

"Marvin Buzz" wrote:


> I am getting a compiler error that says I cannot define user types.

> "Alan Moseley" wrote:
>
> > You need to write a sub or function that is recursively called by itself.
> > For example:-
> > Public Sub ProcessAllFolders()
> > Dim fld As MAPIFolder
> > For Each fld In Application.GetNamespace("MAPI").Folders
> > Call ProcessFolder(fld)
> > Next fld
> > End Sub
> > Public Sub ProcessFolder(ByRef fld As MAPIFolder)
> > Dim subfld As MAPIFolder
> > 'Do Something here
> > For Each subfld In fld.Folders
> > Call ProcessFolder(subfld)
> > Next subfld
> > End Sub
> > > > Alan Moseley IT Consultancy
> > http://www.amitc.co.uk
> > If I have solved your problem, please click Yes below. Thanks.
> > "Marvin Buzz" wrote:
> >
> > > I am writing in Visual Basic, not VBA. I can write the code to identify all
> > > of the subfolders in Outlook, but do not know how to program for the
> > > subfolders of the subfolders...subfolders to any possible depth of subfolders.
> > > > Any samples or guidance would be very much appreciated.
> > > > Thanks in advance.
> > >
 
Thanks for your response. I figured out how to add a reference, but I get an

error on the IMPORTS statement that I copied from your prior response. It

says sub or function not defined. I do not understand what you mean by my

"class". The code I am trying to execute is in a form run from VB.

Marvin

"Alan Moseley" wrote:


> Firstly add a reference to Outlook within your project. Secondly import the
> namespace before the beginning of your class, ie:-

> Imports Microsoft.Office.Interop.Outlook

> > Alan Moseley IT Consultancy
> http://www.amitc.co.uk

> If I have solved your problem, please click Yes below. Thanks.

> "Marvin Buzz" wrote:
>
> > I am getting a compiler error that says I cannot define user types.
> > "Alan Moseley" wrote:
> >
> > > You need to write a sub or function that is recursively called by itself.
> > > For example:-
> > > > Public Sub ProcessAllFolders()
> > > Dim fld As MAPIFolder
> > > For Each fld In Application.GetNamespace("MAPI").Folders
> > > Call ProcessFolder(fld)
> > > Next fld
> > > End Sub
> > > > Public Sub ProcessFolder(ByRef fld As MAPIFolder)
> > > Dim subfld As MAPIFolder
> > > 'Do Something here
> > > For Each subfld In fld.Folders
> > > Call ProcessFolder(subfld)
> > > Next subfld
> > > End Sub
> > > > > > > Alan Moseley IT Consultancy
> > > http://www.amitc.co.uk
> > > > If I have solved your problem, please click Yes below. Thanks.
> > > > > "Marvin Buzz" wrote:
> > > > > I am writing in Visual Basic, not VBA. I can write the code to identify all
> > > > of the subfolders in Outlook, but do not know how to program for the
> > > > subfolders of the subfolders...subfolders to any possible depth of subfolders.
> > > > > > Any samples or guidance would be very much appreciated.
> > > > > > Thanks in advance.
> > > >
 
You don't need an Imports statement in VB6, only in VB.NET.

Sue Mosher

"Marvin Buzz" <MarvinBuzz> wrote in message

news:73913C38-A8DC-4DD9-A4FB-63B331509CC5@microsoft.com...
> Thanks for your response. I figured out how to add a reference, but I get
> an
> error on the IMPORTS statement that I copied from your prior response. It
> says sub or function not defined. I do not understand what you mean by my
> "class". The code I am trying to execute is in a form run from VB.

> Marvin

> "Alan Moseley" wrote:
>
> > Firstly add a reference to Outlook within your project. Secondly import
> > the
> > namespace before the beginning of your class, ie:-
>

>> Imports Microsoft.Office.Interop.Outlook
>

>> > > Alan Moseley IT Consultancy
> > http://www.amitc.co.uk
>

>> If I have solved your problem, please click Yes below. Thanks.
>

>
>> "Marvin Buzz" wrote:
> >
> > > I am getting a compiler error that says I cannot define user types.
> >> > "Alan Moseley" wrote:
> >> > > You need to write a sub or function that is recursively called by
> > > > itself.
> > > > For example:-
> > >> > > Public Sub ProcessAllFolders()
> > > > Dim fld As MAPIFolder
> > > > For Each fld In Application.GetNamespace("MAPI").Folders
> > > > Call ProcessFolder(fld)
> > > > Next fld
> > > > End Sub
> > >> > > Public Sub ProcessFolder(ByRef fld As MAPIFolder)
> > > > Dim subfld As MAPIFolder
> > > > 'Do Something here
> > > > For Each subfld In fld.Folders
> > > > Call ProcessFolder(subfld)
> > > > Next subfld
> > > > End Sub
> > >> > > > > > > Alan Moseley IT Consultancy
> > > > http://www.amitc.co.uk
> > >> > > If I have solved your problem, please click Yes below. Thanks.
> > >> >> > > "Marvin Buzz" wrote:
> > >> > > > I am writing in Visual Basic, not VBA. I can write the code to
> > > > > identify all
> > > > > of the subfolders in Outlook, but do not know how to program for
> > > > > the
> > > > > subfolders of the subfolders...subfolders to any possible depth of
> > > > > subfolders.
> > > >> > > > Any samples or guidance would be very much appreciated.
> > > >> > > > Thanks in advance.
> > > > >
 
Thanks to all who have responded. You have helped a great deal.

"Marvin Buzz" wrote:


> I am writing in Visual Basic, not VBA. I can write the code to identify all
> of the subfolders in Outlook, but do not know how to program for the
> subfolders of the subfolders...subfolders to any possible depth of subfolders.

> Any samples or guidance would be very much appreciated.

> Thanks in advance.
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Z Search in 2 folders with their subfolders Using Outlook 16
A How to make all folders and subfolders open collapsed Using Outlook 1
N auto expand all folders and subfolders in the inbox Using Outlook 3
R how do I print a list of folders/subfolders in Inbox Outlook VBA and Custom Forms 1
G Search Folders and Jump to Folder Outlook VBA and Custom Forms 2
B Sync Outlook Public Folders to Contacts Using Outlook 2
U When opening shared Calendar "The set of folders cannot be opened" Using Outlook 0
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
TomHuckstep Remove Send/Receive All Folders (IMAP/POP) button from Outlook 365 Ribbon Using Outlook 2
C Trying to move messages between imap accounts/folders Using Outlook 5
icacream Outlook 2021 Win 10 - Nothing goes in my Drafts or Sent items folders ! Using Outlook 1
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
P now on office 365 but getting error messages about missing Outlook 2013 cache folders Using Outlook 2
CWM550 Saving Data: Don't check certain folders Using Outlook 2
J Unable to delete folders in Outlook 2019 / Windows Using Outlook 0
D This folder up to date vs all folders up to date Using Outlook 1
e_a_g_l_e_p_i Adjusting font size in folders Using Outlook 1
Abraham Outlook 2013 Lost my folders when moving from PST to IMAP Using Outlook 11
J How to import many msg into different public folders in Outlook Outlook VBA and Custom Forms 7
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
O Cannot expand the folder. The set of folders cannot be opened. You do not have permission to log on. Using Outlook 1
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
R Moved 6 months worth (approx 1500 emails) lost from moving from TPG inbox to Icloud inbox (folders) Using Outlook 3
C What folders are needed when reinstalling Outlook 2010 Using Outlook 0
P Color Code or highlight folders in Outlook 2016 Using Outlook 2
A Moving Public Folders to New Database Exchange Server Administration 3
Paul Hobbs Automatically accept "Empty Folders" prompt Outlook VBA and Custom Forms 6
R Problem moving file “Email folders.pst” to new PC Using Outlook 5
D How To Combine Share Task Folders in just one Folder Using Outlook 0
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
Witzker print-list-of-outlook-folders with sort posibility Outlook VBA and Custom Forms 7
vodkasoda Hiding empty Folders Outlook VBA and Custom Forms 0
C Not sync folders not found after MS Outlook 365 update Using Outlook 1
Fozzie Bear Shared Public Folders Access and Use Exchange Server Administration 0
O The Outlook API wrongfully shows an outlook folder to have zero sub-folders Outlook VBA and Custom Forms 1
O The Outlook API wrongfully shows an outlook folder to have zero sub-folders Outlook VBA and Custom Forms 2
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
T Outlook 2016 remove envelope icon for certain folders Using Outlook 5
GregS Outlook 2016 Sent Mail absent from Sent Mail or Sent Items Folders Using Outlook 4
C Synchronizing subscribed folders causes hanging during send/receive process Using Outlook 2
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
N Sent emails not reflected in all IMAP Folders Using Outlook 4
A Custom VBA to sort emails into folders Outlook VBA and Custom Forms 0
jChambler iCloud folders in Outlook are not the same as on iCloud Using Outlook 6
R The way expand/collapse folders is actually meant to work? Using Outlook 2
David Langer Outlook 2016 (365) How to restore the ability to Re-Map iCloud IMAP Folders Using Outlook 5
L Merge two contacts folders Using Outlook 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
P IMAP Folders Dialog Box Using Outlook 1

Similar threads

Back
Top