Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: VBA

  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Chicago, Illinois, USA
    Posts
    187
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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).

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='Zeno' post='769364' date='06-Apr-2009 09:08']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).[/quote]
    Which version of Outlook, is the archive file always open, and do you always want to go to a specific folder?
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='JohnBF' post='769406' date='06-Apr-2009 20:50']Which version of Outlook, is the archive file always open, and do you always want to go to a specific folder?[/quote]
    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).

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='StuartR' post='769425' date='06-Apr-2009 14:46']...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.[/quote]
    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. )
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='JohnBF' post='769436' date='06-Apr-2009 14:20']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. )[/quote]
    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.

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='jscher2000' post='769438' date='06-Apr-2009 14:40']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.[/quote]

    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.
    -John ... I float in liquid gardens
    UTC -7ąDS

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='JohnBF' post='769445' date='06-Apr-2009 22:54']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.[/quote]
    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.

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='StuartR' post='769425' date='06-Apr-2009 14:46']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.[/quote]
    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
    -John ... I float in liquid gardens
    UTC -7ąDS

  9. #9
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,593
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    [quote name='jscher2000' post='769438' date='06-Apr-2009 16:40'][/quote]

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

    Joe
    Joe

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by joeperez' post='769474 View Post
    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?
    -John ... I float in liquid gardens
    UTC -7ąDS

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    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.

  12. #12
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    23,593
    Thanks
    5
    Thanked 1,059 Times in 928 Posts
    [quote name='JohnBF' post='769479' date='06-Apr-2009 19:30'][/quote]

    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

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='Zeno' post='769364' date='06-Apr-2009 09:08']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).[/quote]
    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 Folders\This Folder\That 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
    -John ... I float in liquid gardens
    UTC -7ąDS

  14. #14
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='JohnBF' post='769467' date='07-Apr-2009 00:37']Here's some Outlook 2003 starter code for you to test[/quote]
    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!

  15. #15
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts
    [quote name='StuartR' post='769506' date='07-Apr-2009 00:52']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.[/quote]
    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
    -John ... I float in liquid gardens
    UTC -7ąDS

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •