Friday, February 24, 2012

Select Folder with VBA/Macscript

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.

Sub Select_Folder_On_Mac()
    Dim folderPath As String
    Dim RootFolder As String

    On Error Resume Next
    RootFolder = MacScript("return (path to desktop folder) as String")
    'Or use RootFolder = "Macintosh HD:Users:Ron:Desktop:TestMap:"
    folderPath = MacScript("(choose folder with prompt ""Select the folder""" & _
    "default location alias """ & RootFolder & """) as string")
    On Error GoTo 0

    If folderPath <> "" Then
        MsgBox folderPath
    End If
End Sub

No comments:

Post a Comment