Return to Snippet

Revision: 62516
at February 28, 2013 01:21 by lolrenx


Updated Code
'FSBrowse (File System Browse) allows the operator to browse for a file/folder.
'  strStart specifies where the process should start the browser.
'  lngType specifies the MsoFileDialogType to use.
'  strPattern specifies which FileType(s) should be included.
Public Function FSBrowse(Optional strStart As String = "", _
                         Optional lngType As MsoFileDialogType = _
                             msoFileDialogFolderPicker, _
                         Optional strPattern As String = "All Files,*.*" _
                         ) As String
                         
    Dim varEntry As Variant
 
    FSBrowse = ""
    With Application.FileDialog(lngType)
        'Set the title to match the type used from the list
        .Title = "Browse for "
        Select Case lngType
        Case msoFileDialogOpen
            .Title = .Title & "File to open"
        Case msoFileDialogSaveAs
            .Title = .Title & "File to SaveAs"
        Case msoFileDialogFilePicker
            .Title = .Title & "File"
        Case msoFileDialogFolderPicker
            .Title = .Title & "Folder"
        End Select
        'Reset then add filter patterns separated by tildes (~) where multiple
        '  extensions are separated by semi-colons (;) and the description is
        '  separated from them by a comma (,).
        '  Example strPattern "MS Access,*.MDB; *.ACCDB~MS Excel,*.XLS; *.XLSX"
        Call .Filters.Clear
        For Each varEntry In Split(strPattern, "~")
            Call .Filters.Add(Description:=Split(varEntry, ",")(0), _
                              Extensions:=Split(varEntry, ",")(1))
        Next varEntry
        'Set some default settings
        .InitialFileName = strStart
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewDetails
        'Only return a value from the FileDialog if not cancelled.
        If .Show Then FSBrowse = .SelectedItems(1)
    End With
End Function

Revision: 62515
at February 27, 2013 23:35 by lolrenx


Initial Code
Private Function Browse_Folder() As String

Dim SelectedFolder
Dim MyPath As FileDialog

Application.ScreenUpdating = False
'Prepare to open a modal window, where a folder is selected
Set MyPath = Application.FileDialog(msoFileDialogFolderPicker)
With MyPath
'Open modal window
        .AllowMultiSelect = False
        If .Show Then
            'The user has selected a folder
            For Each SelectedFolder In .SelectedItems
                'Name of the selected folder
                Browse_Folder = SelectedFolder & Application.PathSeparator
                If Browse_Folder <> vbNullString Then Exit For
            Next
        End If
End With

End Function

Initial URL


Initial Description
returns folder/file  path as string

Initial Title
browse folder/file

Initial Tags


Initial Language
Visual Basic