RE: Cycle through all folders under Mailbox



Hi Alan,

I did think of that. "J View" is available to "All Mail and Post Folders".

The macro seems to crash on the first folder it goes to, which in my case is
the 'deleted item' sub folder in a pst. I hovered the cursor over "subfld"
and "fld" to see what floders were referenced when the macro failed. It fails
on the first cycle, and "J View" is available in deleted items; so i'm at a
bit of a loss.

Thanks for keeping coming back to me. If you got further thoughts/soultions
it's a help. I sit here for ages staring at the code thinking "maybe....". I
appreciate you may want to forget about this issue now though.


Best regards

Jeremy



"Alan Moseley" wrote:

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

.



Relevant Pages

  • RE: Cycle through all folders under Mailbox
    ... Find out which folder the code is failing at. ... For Each fld In Application.GetNamespace.Folders ... Public Sub ProcessFolder ... Dim subfld As MAPIFolder ...
    (microsoft.public.outlook.program_vba)
  • Re: access
    ... Set nms = objApp.GetNamespace ... But then you have different nms and fld statements later: ... Both of these should be fine if you prefix them with the Set keyword and if there really is a Contacts from Access folder in the Personal Folders hierarchy. ... > Sub Main ...
    (microsoft.public.outlook.program_vba)
  • *** TOUGH ONE *** Posting Form Results - using multiple selection boxes (ASP)
    ... I was changing the wrong files in the wrong folder. ... directory and the "_fpclass" folder that should be visible ... in the current web - folder view of FrontPage 2003. ... Sub FP_SetLocaleForPage ...
    (microsoft.public.frontpage.programming)
  • RE: Collect Info from Wkbks in a Folder with Criteria to 1 sheet.
    ... MsgBox ("Cannot open folder - Exiting Macro") ... Exit Sub ... Can you set a filter mechanism so that if ANY files in TEST FOLDER is ...
    (microsoft.public.excel.programming)
  • RE: Web Query Issue
    ... goes to next sub folder, i.e. the rest of htm files in current sub folder ... all htm files from Temporary Internet Files. ... you delete temporary internet files and view files. ...
    (microsoft.public.excel.misc)

Loading