Hello everyone!
I am trying to wrap my head around late binding, so as not to have to set references. I got it figured out for Outlook, but cannot for the life of me get it to work for the file dialog function. Currently I'm getting an error on the 5th line - User defined type not defined. I got lines 2,3 and 4 from another site. Well, I got the whole thing from somewhere else and added 2-4. Thoughts and guidance as always will be greatly appreciated!
Code:
Public Function FSBrowse()
Dim oFS As Object
Set oFS = CreateObject("Scripting.FileSystemObject")
Dim varEntry As Variant
Dim fdf As FileDialogFilter
FSBrowse = ""
With Application.FileDialog(dialogType:=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