Jump to Inbox folder when click on Favorite

Status
Not open for further replies.

Fred Dagg

Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
There are a couple of older threads looking for this (inluding my own posted 4 years ago), but can't post to those now.

I came up with a solution that is good enough for me on this. It requires some vba that autocreates a dummy subfolder under the folder your favorite points to. Then we can jump to that and be right below the real folder.

Open Outlook vba (Shift F11) and pste these two procs in there somewhere.
Create a Quick Access Toolbar entry that points to macro JumpToFavorite.
Click on any folder in Favorites then click on the quick access button. Voila.

'
' Can jump to full path of a folder but if its a fav, it only jumps within Favs list
' So we create a dummy subfolder and jump to that
'
Sub JumpToFavorite()

Dim strUNC As String
Dim oFld As Outlook.Folder

On Error Resume Next
strUNC = ActiveExplorer.CurrentFolder.FolderPath
Set oFld = lib_FolderObjectFromPath(strUNC)
Set ActiveExplorer.CurrentFolder = oFld.Folders("jumpto")
If Err <> 0 Then
Set oFld = oFld.Folders.Add("jumpto")
Set ActiveExplorer.CurrentFolder = oFld
End If
Set oFld = Nothing

End Sub

'
' Return a folder object after passing a full path eg. from objFolder.FolderPath
'
Function lib_FolderObjectFromPath(pstrSrcFolder As String) As Outlook.Folder

Dim oNS As Outlook.NameSpace
Dim oFolder As Outlook.Folder
Dim oParFolder As Outlook.Folder
Dim strParts() As String
Dim intCnt1 As Integer

Set oNS = GetNamespace("MAPI")
strParts = Split(Mid(pstrSrcFolder, 3), "\")
Set oParFolder = oNS.Folders(strParts(0))

For intCnt1 = 1 To UBound(strParts)
Set oFolder = Nothing
On Error Resume Next
Set oFolder = oParFolder.Folders(strParts(intCnt1))
On Error GoTo 0
If oFolder Is Nothing Then
Set lib_FolderObjectFromPath = oFolder
Exit Function
End If
Set oParFolder = oFolder
Next intCnt1

Set lib_FolderObjectFromPath = oFolder
Set oFolder = Nothing
Set oParFolder = Nothing
Set oNS = Nothing

End Function
 
I had thought I could use SendKeys "{Up}" to get it jump up to the real folder but the navigation pane isn't the active pane after running the code above so keystrokes don't work.
Tried ActiveExplorer.Activate but that doesn't solve it.
Also you can't just use Set ActiveExplorer.CurrentFolder = oFld.Parent as that takes you back to Favorites pane.
 
You want to jump to the folder in the Folder list when you select the folder in the Favorites?


I don't know if you borrowed any of this code - but it should work - pass the folder name to it and have it open the folder.
 
Thanks Diane but that code suffers the same problem. If you give it a folder name that is in your Favorites it will take you to Favorites and select that folder. But it still won't take you to that folder within the full tree of folders.

Lets say I have a folder called Customers and under that are folders for each Customer. If an email comes in from Fred and I want to drag it to Customers\Fred I have to navigate manually to the Customers folder in the tree, then find Fred, so I can drag/drop the email. I can't add every customer to Favorites so the idea is to add Customers to Favorites. Then if I select Customers in Favorites I want the folder tree to open up to Customers, so I just scroll down to Fred.

So in this example, I could use that code and type in Fred and it would work (assuming I don't have another folder called Something\Fred that gets found first). But what about customer The Very Little Bottling Co. Yes I could use wildcards but thats still hard work if I have another customer called The Very Little Bottling Org. I'd have to type out 'A Very Little Bottling%'. Phew!

Much simpler would be a Fav called Customers then have it jump to Customers and I scroll from there.
And that's where my code finally gets close, though with the nuisance of creating the dummy subfolder.
 
What I was thinking (on the VBoffice code) - use it to expand a folder in the folder list - could be your jumpto or any existing folder in the path. it does the same thing your code does - I don't know which would be faster....

If the folder names match the From display name or the email address, it would work too.


Code:
' orginial code: http://vboffice.net/en/developers/find-folder-by-name
Private m_Folder As Outlook.MAPIFolder
Private m_Find As String

Private Const SpeedUp As Boolean = True

Public Sub FindFolder()
  Dim Name$
  Dim Folders As Outlook.Folders

' use an existing subfolder here
  m_Find = "Test"

  m_Find = LCase$(m_Find)

  Set Folders = Application.Session.Folders
  LoopFolders Folders

  If Not m_Folder Is Nothing Then
      Set Application.ActiveExplorer.currentFolder = m_Folder
  End If
End Sub

Private Sub LoopFolders(Folders As Outlook.Folders)
  Dim F As Outlook.MAPIFolder
  Dim Found As Boolean
  
  If SpeedUp = False Then DoEvents

  For Each F In Folders
      Found = (LCase$(F.Name) = m_Find)

    If Found Then
      Set m_Folder = F
      Exit For
    Else
      LoopFolders F.Folders
      If Not m_Folder Is Nothing Then Exit For
    End If
  Next
End Sub
 
Two tweaks in this code - first moves the message to a folder named the senders display name (it's commented out in the code).

Second option is putting the senders address in the folder description and moving the message based on that. Adding the email address to the description field would be a pita (right-click on folder > Properties then add the address to the description field)... but the folder name could be anything - and if it's used for multiple senders, you can use instr function to look for the address in the description string.


Code:
Private m_Folder As Outlook.MAPIFolder
Private m_Find As String

Private Const SpeedUp As Boolean = True

Public Sub FindFolder()
  Dim objApp As Outlook.Application
  Dim objItem As MailItem
  Dim Name$
  Dim Folders As Outlook.Folders
    
  Set objApp = Application

  Set m_Folder = Nothing
  m_Find = ""

  Set objItem = objApp.ActiveExplorer.Selection.Item(1)
'  Name = objItem.SenderName
  Name = objItem.SenderEmailAddress
  Debug.Print Name
  If Len(Trim$(Name)) = 0 Then Exit Sub
  m_Find = Name

  m_Find = LCase$(m_Find)

  Set Folders = Application.Session.Folders
  LoopFolders Folders

  If Not m_Folder Is Nothing Then
    '  Set Application.ActiveExplorer.currentFolder = m_Folder
      objItem.Move m_Folder
  End If
End Sub

Private Sub LoopFolders(Folders As Outlook.Folders)
  Dim F As Outlook.MAPIFolder
  Dim Found As Boolean
 
  If SpeedUp = False Then DoEvents

  For Each F In Folders
     ' Found = (LCase$(F.Name) = m_Find)
      Found = (LCase$(F.Description) = m_Find)

    If Found Then
      Set m_Folder = F
      Exit For
    Else
      LoopFolders F.Folders
      If Not m_Folder Is Nothing Then Exit For
    End If
  Next
End Sub
 
Thanks Diane. What you seem to be driving at there is an automated way to jump to a folder based on the sender, which I can see makes sense given the example I used of filing incoming email.
The thing is its not just an automated filing I'm look for. That was just one use for being able to jump to a specific folder.

Take another example. Suppose for each customer subfolder in Customers folder, I create subfolders "To Do" & "Ignore". Now I want to go to Customers\Fred\Ignore. With that Find code, I'd find many results if I typed Ignore. I could type Fred but thats fine for Fred, not for The Very Little Bottling Co. I guess another answer is NOT to have Customers in favorites, then use the find code for Customers. But I have to type out C u s t o m..... instead of simply clicking a button/link/etc.
I'll play with it some more and maybe use a combination of all. Many thanks.
 
I know it's not what you were looking for... but tweaking macros is fun. :)

The best macro is whichever one is the fastest.

then use the find code for Customers. But I have to type out C u s t o m..... instead of simply clicking a button/link/etc.
If you are always opening Customers... you'd want to just activate it. That's fastest. If you aren't filing anything in Customers folder, only in the subs, it doesn't need to use on favorites. But if it is, pick an existing subfolder to activate.

Code:
Sub openFolder()

 Dim objOlApp As Outlook.Application
 Dim objFolder As Outlook.Folder
 Set objOlApp = CreateObject("Outlook.Application")

' subfolder of inbox
'Set objFolder = Session.GetDefaultFolder(olFolderInbox).Folders("Customers")

'same level as inbox
Set objFolder = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("Customers")

 Set objOlApp.ActiveExplorer.CurrentFolder = objFolder

 Set objFolder = Nothing
 Set objOlApp = Nothing

End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
F Jump to Inbox folder when click on Favorite Using Outlook 0
T Outlook 2013: How did "Inbox" emails jump straight to the "Recover Deleted Items" Folder? Using Outlook 2
M Search message, then (1) Jump to folder & (2) Select message that you searched for Outlook VBA and Custom Forms 2
G Search Folders and Jump to Folder Outlook VBA and Custom Forms 2
Victor_50 Outlook 2019 Jump to folder from search folder Outlook VBA and Custom Forms 0
R Search/Jump to a folder by typing its name Outlook VBA and Custom Forms 1
Victor_50 jump to actual folder from favorite Outlook VBA and Custom Forms 1
I jump to body in open message with one keyboard shortcut? Using Outlook 3
A In Contacts Phone List View, allow alpha jump w/single key, same as Card views Using Outlook 4
F Outlook 365 Group INBOX by date but not by date and time Using Outlook 1
T Outlook 2010 Sub accounts not showing new emails in Inbox Using Outlook 4
F Color code certain INBOX emails Using Outlook 2
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
P "Item could not be moved" message occurs frequently for IMAP inbox, Office 365 Using Outlook 0
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
S Format Inbox Using Outlook 0
J How to create a drop down user defined field that will appear on an inbox view Outlook VBA and Custom Forms 8
P Emails assigned with a certain category (within a shared inbox) to be copied to a specific folder. Outlook VBA and Custom Forms 2
O Moving "tasks" to inbox in Outlook 2016 Using Outlook 1
A Imap account not auto syncing inbox at startup Using Outlook 0
S Outlook 2016 dont delete inbox item Using Outlook 0
R Moved 6 months worth (approx 1500 emails) lost from moving from TPG inbox to Icloud inbox (folders) Using Outlook 3
S Problem Checking the available stores in my Inbox (Outlook VBA) Outlook VBA and Custom Forms 0
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
A Inbox didn't got read Outlook VBA and Custom Forms 0
A Unflag Inbox and Flag Inbox with Orange Category After Item is send Outlook VBA and Custom Forms 3
glnz O365 - How to combine the Inboxes for four email accounts into a single Inbox Using Outlook 7
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
G Inbox shows old email Using Outlook 3
C Configuring Inbox columns Using Outlook 2
D Inbox column color coding Using Outlook 2
R Outlook 2010 How do you export 2 email Accounts' 2010 Inbox Files to new computer (2019)? Using Outlook 0
J Collaborative Inbox Using Outlook 1
M Missing emails in Inbox, but are present in webmail Using Outlook 0
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
H Upon opening Outlook, make my popmail inbox open instead of outlook.com inbox Using Outlook 1
P Outlook Mobile App Doesn't Refresh Inbox Using Outlook 0
H In outlook 365 POP mail Inbox, email takes a long time or never arrives. Using Outlook 1
K No emails in inbox Using Outlook.com accounts in Outlook 1
D Unopened message in inbox deleted and not in deleted items Using Outlook 3
R Exporting recovered Deleted Items outside the Inbox Using Outlook 1
N Focussed Inbox Rules Failing Using Outlook 5
M Inbox not showing to deliver new email to this account Using Outlook 3
mctabish Setting "Reply To" based on inbox Outlook VBA and Custom Forms 2
T Inbox Sub-Folder - Web Using Outlook 1
P Two main Outlook gripes: Voting buttons not working externally nor Focused Inbox Using Outlook 1
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1

Similar threads

Back
Top