Return Highest Level Email Folder

Status
Not open for further replies.
Outlook version
Outlook 2016 32 bit
Email Account
IMAP
Hi all -

I would like to return the highest level folder in an Outlook folder path. I can get the parent, but the parent might not be the highest level. I can keep asking for the parent of the parent, but I get an error once I get to the top level.

Alternatively, how do I get the folder path to a string?

Thanx!

hb
 

niton

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Code:
Option Explicit

Private Sub highest_folder()

    Dim obj As Object
    Dim F As Folder
    Dim nextF As Folder
  
    Set obj = ActiveWindow
  
    If TypeOf obj Is Inspector Then
        Set obj = obj.currentItem
    Else
        Set obj = obj.Selection(1)
    End If
  
    Set F = obj.Parent
    Debug.Print "Parent Folder: " & F
  
retry:

    On Error Resume Next
    Set nextF = F.Parent
    ' Turn off error bypass as soon as the purpose is served
    On Error GoTo 0
  
    If Not nextF Is Nothing Then
        Set F = nextF
        Set nextF = Nothing
        Debug.Print "next Higher Folder: " & F
        GoTo retry
    Else
        Debug.Print "Error bypassed as nextF is nothing."
    End If
  
    Debug.Print "The highest folder is: " & F

End Sub

Private Sub GetItemsFolderPath()

    ' http://vboffice.net/sample.html?lang=en&mnu=2&smp=65&cmd=showitem

    Dim obj As Object
    Dim F As Folder
    Dim Msg As String
  
    Set obj = ActiveWindow
  
    If TypeOf obj Is Inspector Then
        Set obj = obj.currentItem
    Else
        Set obj = obj.Selection(1)
    End If
  
    Set F = obj.Parent
  
    Msg = "The path is: " & F.FolderPath & vbCrLf
    Msg = Msg & "Switch to the folder?"
  
    If MsgBox(Msg, vbYesNo) = vbYes Then
        Set ActiveExplorer.CurrentFolder = F
    End If
  
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
R The return of weird graphical glitches in Outlook? Using Outlook 2
B ActiveExplorer return NULL on new Window user login and running Outlook first time Using Outlook 1
B return to inbox Using Outlook 5
icacream outlook 2007 - how do I stop spacing when I hit return ? Using Outlook 4
G Possible to create reports that return contacts based on account criteria? BCM (Business Contact Manager) 0
R Return Address Using Outlook 1
T Inserted indicies in my text of return or forwarded messages Using Outlook 1
L Microsoft Office 2003 Email: Return-path Using Outlook 2
I Mailbox Audit log don't return results. Exchange Server Administration 4
J Outlook 2003 personal folder downloading from Exchange 2003 Some email blank, some email ok, but when return to read again some are blank. Using Outlook 3
D Emails return to original folder after being moved. Using Outlook 1
G Stop automatic capitalisation fo first letter after hitting return!!!!!__I've searched for help everywhere. (Office 2007, Outlook). Using Outlook 1
M DL lost alpha, changed based on icons on left side of name,need to return to alpha. What do icons mean? Using Outlook 1
S Replies/Forwards return error 0x80004005-0xfffff9bb-0x000501 Using Outlook 1
A EWS 2010 does not return any error message Exchange Server Administration 4
N The vertical scroll bar crashes to the bottom of the page and will not return to any point above the bottom. This happens in the email and the list of Using Outlook 1
L then return paragragh symbols are showing up when i go to send a new email Using Outlook 1
A Attachments to Return Receipt message Using Outlook 7
E Unspecified Error when forwarding or sending return mail Using Outlook 3
S ActiveExplorer return NULL on new Window user login and running Outlook first time Outlook VBA and Custom Forms 19
1 Incorrectly Setup a Rule at Domain level to not allow address from outside domain Exchange Server Administration 2
D Security patch seems to kill vbscript on Enterprise Level Outlook VBA and Custom Forms 4
R Blocked Top-Level Domain List Using Outlook 2
S outlook 2000 locks up...looks like I am over the 2GB level? Help__ Using Outlook 1
J Copy Inbox to PST file: Cannot copy folder. A top-level folder cannot be copied to one of its subfol Using Outlook 4
D change default folder-level permissions in exchange Exchange Server Administration 3
C Outlook 2003 Service Pack Level requirement for Exchange 2010? Exchange Server Administration 8
D Installing Exchange 2010 SP.1 - Domain Level Issues Exchange Server Administration 1
M Outlook 2002 Data File Upper Memory Level Exceeded Using Outlook 4
C Difference between Outlook Junk function and personal server level blocking Using Outlook 4
C Exchange & Windows Functional Level Exchange Server Administration 3
S Merging From Outlook 2003 Using Form or Folder Level Fields Outlook VBA and Custom Forms 9
Similar threads
































Top