Hi Guys
am trying to pass the FileDialogFilters collection to a method called "GetFileDialog" and am receiving an error that the object weren't SET... i tried to use the "NEW" keyword but doesn't seem to work for the FD object at-All. so my question is how can i initialize the collection object ?
Also, i noticed that the project will not compile this line "SET .Filters = sFilters" what am i doing wrong, i am just setting it to the same object type ?
THANKS IN ADVANCE !
Below is my code.
The btn Code:
GetFileDialog Code:
am trying to pass the FileDialogFilters collection to a method called "GetFileDialog" and am receiving an error that the object weren't SET... i tried to use the "NEW" keyword but doesn't seem to work for the FD object at-All. so my question is how can i initialize the collection object ?
Also, i noticed that the project will not compile this line "SET .Filters = sFilters" what am i doing wrong, i am just setting it to the same object type ?
THANKS IN ADVANCE !
Below is my code.
The btn Code:
Code:
Private Sub cmdAttachNew_Click()
Dim sLoc As String, f As FileDialogFilters
f.Add "Excel", "*.xlsx; *.xls", 1
f.Add "All Files", "*.*", 2
sLoc = GetFileDialog("%USERPROFILE%\Desktop", f)
End Sub
GetFileDialog Code:
Code:
Function GetFileDialog(Optional sInitialFileName As String, Optional sFilters As FileDialogFilters) As String
Dim fd As FileDialog, vrtSelectedItem As Variant
Dim strSelectedFile As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.InitialFileName = sInitialFileName
[U] SET .Filters = sFilters[/U]
' If sFilters > "" Then
' arFilters = Split(sFilters, "|")
' For i = 0 To UBound(arFilters) - 1
' .Filters.Add "", arFilters(i), i + 1
' Next
' End If
.Show
' .Filters.Clear
'If .Show = -1 Then
'For Each vrtSelectedItem In .SelectedItems 'onby be 1
'strSelectedFile = vrtSelectedItem
'Next vrtSelectedItem
'Else 'The user pressed Cancel.
'End If
End With
If fd.SelectedItems.Count = 0 Then Exit Function
GetFileDialog = fd.SelectedItems(1)
Set fd = Nothing