/ Published in: Visual Basic
returns folder/file path as string
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
'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