browse folder/file


/ Published in: Visual Basic
Save to your folder(s)

returns folder/file path as string


Copy this code and paste it in your HTML
  1. 'FSBrowse (File System Browse) allows the operator to browse for a file/folder.
  2. ' strStart specifies where the process should start the browser.
  3. ' lngType specifies the MsoFileDialogType to use.
  4. ' strPattern specifies which FileType(s) should be included.
  5. Public Function FSBrowse(Optional strStart As String = "", _
  6. Optional lngType As MsoFileDialogType = _
  7. msoFileDialogFolderPicker, _
  8. Optional strPattern As String = "All Files,*.*" _
  9. ) As String
  10.  
  11. Dim varEntry As Variant
  12.  
  13. FSBrowse = ""
  14. With Application.FileDialog(lngType)
  15. 'Set the title to match the type used from the list
  16. .Title = "Browse for "
  17. Select Case lngType
  18. Case msoFileDialogOpen
  19. .Title = .Title & "File to open"
  20. Case msoFileDialogSaveAs
  21. .Title = .Title & "File to SaveAs"
  22. Case msoFileDialogFilePicker
  23. .Title = .Title & "File"
  24. Case msoFileDialogFolderPicker
  25. .Title = .Title & "Folder"
  26. End Select
  27. 'Reset then add filter patterns separated by tildes (~) where multiple
  28. ' extensions are separated by semi-colons (;) and the description is
  29. ' separated from them by a comma (,).
  30. ' Example strPattern "MS Access,*.MDB; *.ACCDB~MS Excel,*.XLS; *.XLSX"
  31. Call .Filters.Clear
  32. For Each varEntry In Split(strPattern, "~")
  33. Call .Filters.Add(Description:=Split(varEntry, ",")(0), _
  34. Extensions:=Split(varEntry, ",")(1))
  35. Next varEntry
  36. 'Set some default settings
  37. .InitialFileName = strStart
  38. .AllowMultiSelect = False
  39. .InitialView = msoFileDialogViewDetails
  40. 'Only return a value from the FileDialog if not cancelled.
  41. If .Show Then FSBrowse = .SelectedItems(1)
  42. End With
  43. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.