Does anyone have code to access archive sub-folders that they would be willing to share? I’d like to be able to switch folders directly from a toolbar button without using the navigation pane or Go (ctrl-6).
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
VBA
Home » Forums » AskWoody support » Productivity software by function » MS Outlook and email programs » VBA
- This topic has 18 replies, 5 voices, and was last updated 16 years, 1 month ago.
Viewing 2 reply threadsAuthorReplies-
WSJohnBF
AskWoody LoungerApril 6, 2009 at 2:50 pm #1155357 -
WSStuartR
AskWoody LoungerApril 6, 2009 at 3:46 pm #1155370Which version of Outlook, is the archive file always open, and do you always want to go to a specific folder?
I don’t know about the original poster, but here is what I would find incredibly useful…
I have an archive folder which is always open and which has the same folder structure as my main Exchange-server-based folders (with the possible exception of recently created folders). It would be really useful to have a toolbar button that would take me to the same folder in the Archive folder as I currently have open in the main folders. (or maybe if the currently open folder is in the Archive folders it could switch back to the corresponding folder in the main folders).
-
WSJohnBF
AskWoody LoungerApril 6, 2009 at 4:20 pm #1155377…here is what I would find incredibly useful… It would be really useful to have a toolbar button that would take me to the same folder in the Archive folder as I currently have open in the main folders.
Goodness! If Jefferson, Hans, or Rory doesn’t beat me to it, I plan to have a shot at the OP request, then I can cobble together some code for your request, but don’t plan on anything too soon. (Don’t we have a Rule on making demands of other Loungers?
Kidding.
)
-
WSjscher2000
AskWoody LoungerApril 6, 2009 at 4:40 pm #1155378Goodness! If Jefferson, Hans, or Rory doesn’t beat me to it, I plan to have a shot at the OP request, then I can cobble together some code for your request, but don’t plan on anything too soon. (Don’t we have a Rule on making demands of other Loungers?
Kidding.
)
Hi John, it looks as though given the ActiveExplorer.CurrentFolder, the .Parent.FullFolderPath plus the .Name uniquely identifies the folder. Given a user specified pair of parent paths, it should not be too traumatic to switch between them.
As my personal request, I want to assign a hotkey to the Sent Items folder. It’s gotten so far down the tree I can barely find it.
-
WSJohnBF
AskWoody LoungerApril 6, 2009 at 4:54 pm #1155381given the ActiveExplorer.CurrentFolder, the .Parent.FullFolderPath plus the .Name uniquely identifies the folder.As my personal request, I want to assign a hotkey to the Sent Items folder. It’s gotten so far down the tree I can barely find it.
1. I’m with you, my plan was to grab ActiveExplorer.CurrentFolder.FullFolderPath and apply some code for reparsing the source folder path to the target folder.
2. I recommend you try this instead (a variation on something I used to do): create a Folder called “~Sent”, and create a Rule to move all your Sent items to it. Outlook will ASCII sort “~Sent” at the top of your folder list. -
WSStuartR
AskWoody LoungerApril 6, 2009 at 5:27 pm #11553851. I’m with you, my plan was to grab ActiveExplorer.CurrentFolder.FullFolderPath and apply some code for reparsing the source folder path to the target folder.
2. I recommend you try this instead (a variation on something I used to do): create a Folder called “~Sent”, and create a Rule to move all your Sent items to it. Outlook will ASCII sort “~Sent” at the top of your folder list.I solved this problem by creating a folder called “zz folders” and filing everything in sub-folders of this. That way I have Inbox, Outbox, Sent Items etc. all sorted to the top.
-
joep517
AskWoody MVP -
WSJohnBF
AskWoody LoungerApril 6, 2009 at 7:30 pm #1155404You could always upgrade to Office 2007 and add “Sent Items” to your Favorites.
[/quote]
Doh! And in Outlook 2003 Mail View! Which is why I stopped using the ~Sent Folder trick. Are Favorite Folders available in full Folder List view in Outlook 2007? Because I suspect Jefferson uses full Folder List view. Or has the view “look” changed so much in Outlook 2007 that my question is irrelevant? -
joep517
AskWoody MVP
-
-
-
WSJohnBF
AskWoody LoungerApril 6, 2009 at 6:37 pm #1155398It would be really useful to have a toolbar button that would take me to the same folder in the Archive folder as I currently have open in the main folders.
Here’s some Outlook 2003 starter code for you to test, edit the two root folder strings by grabbing them from the Immediates window using ActiveExplorer.CurrentFolder.FolderPath. Create the button manually via (Outlook 2003 menu) the View | Tools | Customize | Commands | Macros:
Code:Sub GoToSamePSTFolder() Dim fldrTargFolder As MAPIFolder Dim arrFolders() As String, strFolderPath As String Dim intI As Integer If InStr(ActiveExplorer.CurrentFolder.FolderPath, "\Mailbox ") = 0 Then Exit Sub ' not in Exchange Folder ' replace string with Exchange root folder name strFolderPath = Replace(ActiveExplorer.CurrentFolder.FolderPath, "\Mailbox - StuartR", "") arrFolders() = Split(Replace(Replace(strFolderPath, "/", ""), "\", ""), "", , vbTextCompare) ' replace string with PST root folder name, no slashes Set fldrTargFolder = Outlook.Session.Folders("StuartR Personal Folder 1") If UBound(arrFolders) >= 0 Then ' if < 0 root folder currently selected For intI = 0 To UBound(arrFolders) Set fldrTargFolder = fldrTargFolder.Folders(arrFolders(intI)) Next intI End If ActiveExplorer.SelectFolder fldrTargFolder Set fldrTargFolder = Nothing End Sub
-
WSStuartR
AskWoody LoungerApril 7, 2009 at 2:52 am #1155427Here’s some Outlook 2003 starter code for you to test
John,
Thank you, that works perfectly, and is going to save me lots of time.
Since my capability in Outlook VBA is non existent I would be really grateful if you could modify it. Currently it checks that I have a folder in my mailbox selected, and if not it exits straight away, otherwise it switches me to the same folder in my archive. Ideally it should act as a toggle, so that if I have a folder in the archive seleted it should switch to the same folder in the mailbox.
You cannot imagine how useful this is going to be for me, and I had never even thought of it until the original poster asked for something different!
-
WSJohnBF
AskWoody LoungerApril 7, 2009 at 3:41 am #1155428Ideally it should act as a toggle, so that if I have a folder in the archive seleted it should switch to the same folder in the mailbox.
Here you go, not pretty, but easy to follow, the Exchange Mailbox and PST root names are now Constants and the code just flips the strings, plus added a basic errorhandler:
[codebox]Sub GoToParallelFolder()
Dim objParent As Object
Dim fldrTargFolder As MAPIFolder
Dim arrFolders() As String
‘ code string with Exchange root folder name, no slashes
Const strExchPFolder As String = “Mailbox – StuartR”
‘ code string with PST root folder name, no slashes
Const strPSTPFolder As String = “StuartR Personal Folder 1”
Dim strStartPFolder As String, strTargPFolder As String, strStartFolderPath As String
Dim intI As IntegerWith Outlook.ActiveExplorer
If CBool(InStr(.CurrentFolder.FolderPath, “\Mailbox “)) Then ‘ in Exchange Folder
strStartPFolder = strExchPFolder
strTargPFolder = strPSTPFolder
Else ‘ in PST Folder
strStartPFolder = strPSTPFolder
strTargPFolder = strExchPFolder
End IfstrStartFolderPath = .CurrentFolder.Name
Set objParent = .CurrentFolder
Do Until objParent.Parent.Name = strStartPFolder
Set objParent = objParent.Parent
strStartFolderPath = objParent.Name & Chr(19) & strStartFolderPath
Loop
Set objParent = NothingarrFolders() = Split(Trim(strStartFolderPath), Chr(19), , vbTextCompare)
Set fldrTargFolder = Outlook.Session.Folders(strTargPFolder)If UBound(arrFolders) >= 0 Then ‘ if < 0 root folder currently selected
For intI = 0 To UBound(arrFolders)
On Error GoTo HANDLER:
Set fldrTargFolder = fldrTargFolder.Folders(arrFolders(intI))
Next intI
End If
.SelectFolder fldrTargFolder
End With
HANDLER:
If Err Then MsgBox "Corresponding FolderPath not found in " & strTargPFolder
Set fldrTargFolder = Nothing
End Sub[/codebox]
Let me know if you have any problems -
WSStuartR
AskWoody LoungerApril 7, 2009 at 4:11 am #1155436Here you go, not pretty, but easy to follow, the Exchange Mailbox and PST root names are now Constants and the code just flips the strings, plus added a basic errorhandler:
That is absolutely perfect, thank you.
It took me a while to work out that the folders where I had problems all had a somewhere in the folder name, or in the path leading to the folder, but I just renamed a couple of folders to fix this.
-
WSJohnBF
AskWoody LoungerApril 7, 2009 at 9:33 am #1155466… the folders where I had problems all had a somewhere in the folder name, or in the path leading to the folder, but I just renamed a couple of folders to fix this.
It’s odd to me that MS provides a .CurrentFolder.FolderPath Method which separates folders with a backslash but permits the use of a backslash within a Folder name, making parsing impractical. I must never have used a slash or backslash in a folder name because I was thinking of forbidden system file name characters, so I never ran across this. I guess the way around this would to be a more complex walk back up the Parent Folders until the .NameSpace Parent object is reached. Let me have a go at it later.
-
WSJohnBF
AskWoody LoungerApril 7, 2009 at 2:16 pm #1155497odd that MS provides a .CurrentFolder.FolderPath Method which separates folders with a backslash but permits the use of a backslash within a Folder name, making parsing impractical.
[/quote]
The [post=”769508″]code in Post 769508[/post] has been edited to handle in folder names. I hope. -
WSStuartR
AskWoody Lounger
-
-
-
-
-
WSjscher2000
AskWoody LoungerApril 6, 2009 at 8:03 pm #1155410Sorry to hijack the thread, and thanks for the suggestions.
I’m in no rush to switch to Outlook 2007, but Outlook 2003 does have Favorites. I use the “all folders” view out of habit. I think the only thing I use there other than mail folders is the calendar, so I could switch. I’ll try it for a while.
I think I will defer changing the Sent Items folder itself because I sync my Sent Items folder to my Windows Mobile phone. Folder management on the little device already is a little messy, so I am loathe to make it any more complicated.
-
WSJohnBF
AskWoody LoungerApril 6, 2009 at 9:46 pm #1155414Does anyone have code to access archive sub-folders that they would be willing to share? I’d like to be able to switch folders directly from a toolbar button without using the navigation pane or Go (Ctrl-F6).
This code should work in Outlook 2003 once you substitute the target folder string. Attach the code to a button manually via View | Toolbars | Customize | Commands | Macros:
Code:Sub GoToPSTFolder() Dim fldrTarget As MAPIFolder ' replace following string with correct target folder path Const strFolderPath As String = "\Zeno Personal FoldersThis FolderThat Folder" Dim arrFolders() As String Dim intI As Integer arrFolders() = Split(Replace(Replace(strFolderPath, "/", ""), "\", ""), "", , vbTextCompare) Set fldrTarget = Outlook.Session.Folders(arrFolders(0)) For intI = 1 To UBound(arrFolders) Set fldrTarget = fldrTarget.Folders(arrFolders(intI)) Next intI Outlook.ActiveExplorer.SelectFolder fldrTarget Set fldrTarget = Nothing End Sub
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Xfinity home internet
by
MrJimPhelps
42 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
2 hours, 59 minutes ago -
Debian 12.11 released
by
Alex5723
7 hours, 42 minutes ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
11 hours, 24 minutes ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
8 hours, 54 minutes ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
7 hours, 52 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
1 day, 4 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
18 hours, 44 minutes ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
1 day, 6 hours ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
23 hours, 15 minutes ago -
Some advice for managing my wireless internet gateway
by
LHiggins
6 hours, 48 minutes ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
25 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
1 day, 16 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 day, 12 hours ago -
Does windows update component store “self heal”?
by
Mike Cross
1 day, 2 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
2 days, 6 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
14 hours, 23 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
3 hours, 1 minute ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
2 days, 9 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
2 days, 9 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
1 day, 21 hours ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
2 days, 17 hours ago -
0Patch, where to begin
by
cassel23
2 days, 11 hours ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
3 days, 6 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
2 days, 18 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
3 days, 15 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
3 days, 6 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
8 hours, 37 minutes ago -
Installer program can’t read my registry
by
Peobody
31 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
3 days, 4 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.