Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display dialogue to allow a user to select an Outlook folder in VBA

Tags:

vba

outlook

I've written some Outlook VBA which needs the user to select a mail folder (either from within their mailbox or from within an external PST).

At the moment, they have to edit the path directly within the code - which is not remotely user friendly or efficient.

Does anyone know how to get a dialogue box to appear that allows the user to browse all available folders and sub-folders and select one?

Bonus points if it can be limited to mail folders only but it's not essential.

like image 723
Richard Avatar asked Feb 18 '23 23:02

Richard


1 Answers

Try using the Pickfolder method:

Sub FolderPick()

    Dim objNS As NameSpace
    Dim objFolder As folder

    Set objNS = Application.GetNamespace("MAPI")
    Set objFolder = objNS.PickFolder

    If TypeName(objFolder) <> "Nothing" Then
        Debug.Print vbCr & " objFolder: " & objFolder
    Else
        Debug.Print vbCr & "Cancel"
    End If

    Set objFolder = Nothing
    Set objNS = Nothing

End Sub
like image 188
niton Avatar answered Apr 09 '23 17:04

niton