• VBA

    Author
    Topic
    #458868

    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).

    Viewing 2 reply threads
    Author
    Replies
    • #1155357

      Does anyone have code to access archive sub-folders…? I’d like to be able to switch folders directly from a toolbar button without using the navigation pane or Go (ctrl-6).

      Which version of Outlook, is the archive file always open, and do you always want to go to a specific folder?

      • #1155370

        Which 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).

        • #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. )

          • #1155378

            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. )

            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.

            • #1155381

              given 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.

            • #1155385

              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.

              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.

            • #1155402

              You could always upgrade to Office 2007 and add “Sent Items” to your Favorites.

              Joe

              --Joe

            • #1155404

              You 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?

            • #1155413

              Unfortunately “Favorites” are not available in the full Folder List view. The attached is from the Mail view on my home PC. I think that you really can’t change much there either.

              Joe

              --Joe

        • #1155398

          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.

          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
          • #1155427

            Here’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!

            • #1155428

              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.

              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 Integer

              With 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 If

              strStartFolderPath = .CurrentFolder.Name
              Set objParent = .CurrentFolder
              Do Until objParent.Parent.Name = strStartPFolder
              Set objParent = objParent.Parent
              strStartFolderPath = objParent.Name & Chr(19) & strStartFolderPath
              Loop
              Set objParent = Nothing

              arrFolders() = 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

            • #1155436

              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:

              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.

            • #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.

            • #1155497

              odd 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.

            • #1155503

              The [post=”769508″]code in Post 769508[/post] has been edited to handle in folder names. I hope.

              Perfect, thank you.

              Next time you come to London I will buy you a beer or two!

    • #1155410

      Sorry 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.

    • #1155414

      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-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
    Reply To: VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: