Select Folder on Mac

With the example below you can select a Folder in a browse dialog and also set the Root folder. In this example it will always open on the Desktop, see the commented line in the code to use a fixed path. Note : if you want to use a fixed path use the / as separator. When you click on Choose in the Browse dialog in will return the path of the selected folder.


Sub Select_Folder_On_Mac()
Dim FolderPath As String
Dim RootFolder As String
Dim Scriptstr As String

On Error Resume Next

'Enter the Start Folder, Desktop in this example,
'Use the second line to enter your own path
RootFolder = MacScript("return POSIX path of (path to desktop folder) as String")

'RootFolder = "/Users/rondebruin/Desktop/TestFolder/"

'Make the path Colon seperated for using in MacScript
RootFolder = MacScript("return POSIX file (""" & RootFolder & """) as string")
'Make the Script string
Scriptstr = "return POSIX path of (choose folder with prompt ""Select the folder""" & _
" default location alias """ & RootFolder & """) as string"

'Run the Script
FolderPath = MacScript(Scriptstr)
On Error GoTo 0

If FolderPath <> "" Then
MsgBox FolderPath
End If
End Sub
10-February-2021
Web design by Will Woodgate