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

Cycle through all folders under Mailbox



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 18th 09, 03:02 PM posted to microsoft.public.outlook.program_vba
Jeremy
external usenet poster
 
Posts: 28
Default Cycle through all folders under Mailbox

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

Ads
  #2  
Old February 18th 09, 04:38 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Cycle through all folders under Mailbox



See this example:
http://www.vboffice.net/sample.html?...cmd=showite m

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Wed, 18 Feb 2009 07:02:01 -0800 schrieb Jeremy:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't

think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders

Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #3  
Old February 18th 09, 04:42 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default Cycle through all folders under Mailbox

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #4  
Old February 19th 09, 09:16 AM posted to microsoft.public.outlook.program_vba
Jeremy
external usenet poster
 
Posts: 28
Default Cycle through all folders under Mailbox

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #5  
Old February 19th 09, 03:21 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default Cycle through all folders under Mailbox

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply

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

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


"Jeremy" wrote:

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #6  
Old February 19th 09, 08:20 PM posted to microsoft.public.outlook.program_vba
Jeremy
external usenet poster
 
Posts: 28
Default Cycle through all folders under Mailbox

Hi,

I seem to have some odd results with this code. It iterates through an
apparently random selection of folders, and then fails to apply the specified
view. Is there an easy solution? I *really* wanted to be able to apply a
specified view to all folders but it seems impossible and I'm wasting hours
trying to work this out.

The code I have is:


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

For Each subfld In fld.Folders
Call ProcessFolder(subfld)

If subfld.DefaultItemType = olMailItem Then

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

End If

Next subfld

End Sub



Thanks for any help


"Alan Moseley" wrote:

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply

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

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


"Jeremy" wrote:

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #7  
Old February 19th 09, 08:44 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default Cycle through all folders under Mailbox

The iteration through the folders is not at all random. For example, it
begins with your first mailbox, selecting each folder in turn until it
reaches the end. It then will select (probably) your archive and repeat the
process, and then your public folders.

Secondly, ActiveExplorer is your folder list as displayed in Outlook, not
the list of folders that you are iterating through. Therefore, as your code
was iterating through each folder, it was just reapplying your custom view to
whichever folder you had visible in Outlook. You will need to change these
lines:-

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

with:-

subfld.Views("J VIEW").Apply
subfld.CurrentFolder.Views("J VIEW").Save

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

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


"Jeremy" wrote:

Hi,

I seem to have some odd results with this code. It iterates through an
apparently random selection of folders, and then fails to apply the specified
view. Is there an easy solution? I *really* wanted to be able to apply a
specified view to all folders but it seems impossible and I'm wasting hours
trying to work this out.

The code I have is:


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

For Each subfld In fld.Folders
Call ProcessFolder(subfld)

If subfld.DefaultItemType = olMailItem Then

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

End If

Next subfld

End Sub



Thanks for any help


"Alan Moseley" wrote:

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply

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

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


"Jeremy" wrote:

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #8  
Old February 20th 09, 09:23 AM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default Cycle through all folders under Mailbox

Sorry that last line should read:-

subfld.Views("J VIEW").Save

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

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


"Alan Moseley" wrote:

The iteration through the folders is not at all random. For example, it
begins with your first mailbox, selecting each folder in turn until it
reaches the end. It then will select (probably) your archive and repeat the
process, and then your public folders.

Secondly, ActiveExplorer is your folder list as displayed in Outlook, not
the list of folders that you are iterating through. Therefore, as your code
was iterating through each folder, it was just reapplying your custom view to
whichever folder you had visible in Outlook. You will need to change these
lines:-

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

with:-

subfld.Views("J VIEW").Apply
subfld.CurrentFolder.Views("J VIEW").Save

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

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


"Jeremy" wrote:

Hi,

I seem to have some odd results with this code. It iterates through an
apparently random selection of folders, and then fails to apply the specified
view. Is there an easy solution? I *really* wanted to be able to apply a
specified view to all folders but it seems impossible and I'm wasting hours
trying to work this out.

The code I have is:


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

For Each subfld In fld.Folders
Call ProcessFolder(subfld)

If subfld.DefaultItemType = olMailItem Then

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

End If

Next subfld

End Sub



Thanks for any help


"Alan Moseley" wrote:

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply

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

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


"Jeremy" wrote:

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #9  
Old February 20th 09, 10:52 AM posted to microsoft.public.outlook.program_vba
Jeremy
external usenet poster
 
Posts: 28
Default Cycle through all folders under Mailbox

Alan,

I think I'm almost there. What i find is that the following code (below)
works fine if I choose the "Messages" view, but stops on the line

subfld.Views("J View").Apply

when I try using a custom view. It says "Object variable or With block
variable not set". I can't fathom which object variable I have not set. Any
clue?



Public Sub ProcessAllFolders()
Dim fld As MAPIFolder

For Each fld In Application.GetNamespace("MAPI").Folders
If fld.DefaultItemType = olMailItem Then
Call ProcessFolder(fld)
End If
Next fld

End Sub
Public Sub ProcessFolder(ByRef fld As MAPIFolder)
Dim subfld As MAPIFolder

For Each subfld In fld.Folders

Call ProcessFolder(subfld)
If subfld.DefaultItemType = olMailItem Then
subfld.Views("J View").Apply
subfld.Views("J View").Save
End If

Next subfld

End Sub










"Alan Moseley" wrote:

The iteration through the folders is not at all random. For example, it
begins with your first mailbox, selecting each folder in turn until it
reaches the end. It then will select (probably) your archive and repeat the
process, and then your public folders.

Secondly, ActiveExplorer is your folder list as displayed in Outlook, not
the list of folders that you are iterating through. Therefore, as your code
was iterating through each folder, it was just reapplying your custom view to
whichever folder you had visible in Outlook. You will need to change these
lines:-

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

with:-

subfld.Views("J VIEW").Apply
subfld.CurrentFolder.Views("J VIEW").Save

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

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


"Jeremy" wrote:

Hi,

I seem to have some odd results with this code. It iterates through an
apparently random selection of folders, and then fails to apply the specified
view. Is there an easy solution? I *really* wanted to be able to apply a
specified view to all folders but it seems impossible and I'm wasting hours
trying to work this out.

The code I have is:


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

For Each subfld In fld.Folders
Call ProcessFolder(subfld)

If subfld.DefaultItemType = olMailItem Then

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

End If

Next subfld

End Sub



Thanks for any help


"Alan Moseley" wrote:

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply

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

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


"Jeremy" wrote:

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
End Sub

  #10  
Old February 20th 09, 12:18 PM posted to microsoft.public.outlook.program_vba
Alan Moseley
external usenet poster
 
Posts: 61
Default Cycle through all folders under Mailbox

Find out which folder the code is failing at. Now browse to that folder in
your folder list. You will probably find that 'J VIEW' is not a view that
you can choose from. 'J VIEW' must exist for you to be able to select it.

I guess that your next question is going to be 'how do you copy a view from
one folder to another? If so, please start a new thread.
--
Alan Moseley IT Consultancy
http://www.amitc.co.uk

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


"Jeremy" wrote:

Alan,

I think I'm almost there. What i find is that the following code (below)
works fine if I choose the "Messages" view, but stops on the line

subfld.Views("J View").Apply

when I try using a custom view. It says "Object variable or With block
variable not set". I can't fathom which object variable I have not set. Any
clue?



Public Sub ProcessAllFolders()
Dim fld As MAPIFolder

For Each fld In Application.GetNamespace("MAPI").Folders
If fld.DefaultItemType = olMailItem Then
Call ProcessFolder(fld)
End If
Next fld

End Sub
Public Sub ProcessFolder(ByRef fld As MAPIFolder)
Dim subfld As MAPIFolder

For Each subfld In fld.Folders

Call ProcessFolder(subfld)
If subfld.DefaultItemType = olMailItem Then
subfld.Views("J View").Apply
subfld.Views("J View").Save
End If

Next subfld

End Sub










"Alan Moseley" wrote:

The iteration through the folders is not at all random. For example, it
begins with your first mailbox, selecting each folder in turn until it
reaches the end. It then will select (probably) your archive and repeat the
process, and then your public folders.

Secondly, ActiveExplorer is your folder list as displayed in Outlook, not
the list of folders that you are iterating through. Therefore, as your code
was iterating through each folder, it was just reapplying your custom view to
whichever folder you had visible in Outlook. You will need to change these
lines:-

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

with:-

subfld.Views("J VIEW").Apply
subfld.CurrentFolder.Views("J VIEW").Save

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

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


"Jeremy" wrote:

Hi,

I seem to have some odd results with this code. It iterates through an
apparently random selection of folders, and then fails to apply the specified
view. Is there an easy solution? I *really* wanted to be able to apply a
specified view to all folders but it seems impossible and I'm wasting hours
trying to work this out.

The code I have is:


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

For Each subfld In fld.Folders
Call ProcessFolder(subfld)

If subfld.DefaultItemType = olMailItem Then

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply
ActiveExplorer.CurrentFolder.Views("J VIEW").Save

End If

Next subfld

End Sub



Thanks for any help


"Alan Moseley" wrote:

ActiveExplorer.CurrentFolder.Views("J VIEW").Apply

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

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


"Jeremy" wrote:

Alan,

Thanks for the code. It's very helpful.

I wantedto loop through all my folders and apply a specified view. Adapting
your code I have the following:

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
Application.ActiveExplorer.CurrentView = "J VIEW"

For Each subfld In fld.Folders
Call ProcessFolder(subfld)
Next subfld
End Sub


I understand I need to get the current view as an object and apply it but
I'm not sure of the code. If you're inclined to any further help I do
appreciate it!


Thanks






"Alan Moseley" wrote:

You just need to start your search higher up the folder tree eg.

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.


"Jeremy" wrote:

Hi,

I would like to cycle through every folder in my mailbox and I have the
following code. However, i don't think this code will cycle through all
folders, I think it just cycles through those under my inbox. I don't think
the macro will cycle through folders located under .pst archives, or other
mailboxes that I have access to under my mailbox.

Is there a way a cycling through all folders, including those under other
mailboxes and archives?

My current macro is as follows:

Sub ProcessAllFolders()
ProcessSubFolder Application.ActiveExplorer.CurrentFolder
MsgBox "All Done!", vbInformation + vbOKOnly, "Process All Folders Macro"
End Sub

Sub ProcessSubFolder(olkFolder As Outlook.MAPIFolder)
Dim olkSubFolder As Outlook.MAPIFolder

'insert some code here to do something

For Each olkSubFolder In olkFolder.Folders
ProcessSubFolder olkSubFolder
Next
Set olkSubFolder = Nothing
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
how to set up a 6 day school cycle in outlook pocono24 Outlook - Calandaring 5 January 5th 08 02:09 PM
Cannot see all folders of shared Mailbox [email protected] Outlook - General Queries 2 October 18th 07 05:30 PM
Can Outlook b-set up 2automatically input a 6 day school cycle dvaar Outlook - Calandaring 1 March 11th 07 10:28 PM
Custome Recurrence Cycle? Dan Merkel Outlook - General Queries 3 August 8th 06 02:19 PM
Loop through all folders in a mailbox Bob Smith Outlook and VBA 4 May 25th 06 11:23 PM


All times are GMT +1. The time now is 12:55 PM.


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.