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
-
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
28 minutes ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
1 hour, 36 minutes ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
1 hour, 47 minutes ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
1 hour, 59 minutes ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
2 hours, 5 minutes ago -
Lumma malware takedown
by
EyesOnWindows
9 hours, 19 minutes ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
10 hours, 53 minutes ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
10 hours, 47 minutes ago -
Meet Gemini in Chrome
by
Alex5723
14 hours, 52 minutes ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
15 hours, 1 minute ago -
Trump signs Take It Down Act
by
Alex5723
22 hours, 59 minutes ago -
Do you have a maintenance window?
by
Susan Bradley
10 hours, 9 minutes ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
1 hour, 11 minutes ago -
Cox Communications and Charter Communications to merge
by
not so anon
1 day, 2 hours ago -
Help with WD usb driver on Windows 11
by
Tex265
1 day, 7 hours ago -
hibernate activation
by
e_belmont
1 day, 11 hours ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
1 day, 15 hours ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
1 day, 18 hours ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
1 day, 18 hours ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
14 hours, 12 minutes ago -
Out of band for Windows 10
by
Susan Bradley
1 day, 22 hours ago -
Giving UniGetUi a test run.
by
RetiredGeek
2 days, 5 hours ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
2 days, 13 hours ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
9 hours, 12 minutes ago -
Auto Time Zone Adjustment
by
wadeer
2 days, 17 hours ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
2 days, 15 hours ago -
Manage your browsing experience with Edge
by
Mary Branscombe
15 hours, 3 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
1 day, 8 hours ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
8 hours, 41 minutes ago -
Apps included with macOS
by
Will Fastie
1 day, 12 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.