![]() |
|
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 03:40 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-2006 OutlookBanter.com