Hello,
The file filter in the following code works well. When I open the dialog box I see all the *.txt file types....
Sub SelectFiles()
Dim iFileSelect As FileDialog
Set iFileSelect = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
iFileSelect.Filters.Clear
iFileSelect.Filters.Add "Text files", "*.txt"
If iFileSelect.Show = -1 Then
For Each vrtSelectedItem In iFileSelect.SelectedItems
MyPath = vrtSelectedItem ' MyPath will have the filename the program is exported to
Next vrtSelectedItem
End If
'Set object variable to Nothing
Set iFileSelect = Nothing
End Sub
However, the new SelectFiles() function needs to be flexible enough so that I can pass it a variable and based on that variable
I can alter the file filter. Something like this:
Sub SelectFiles(FilterType as integer)
Dim iFileSelect As FileDialog
Set iFileSelect = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
iFileSelect.Filters.Clear
' new part ============================================
if FilterType = 1 then
iFileSelect.Filters.Add "Text files", "*.txt"
Elseif FilterType = 2 then
iFileSelect.Filters.Add "User files", "User*.h"
EndIf
' ==================================================
If iFileSelect.Show = -1 Then
For Each vrtSelectedItem In iFileSelect.SelectedItems
MyPath = vrtSelectedItem ' MyPath will have the filename the program is exported to
Next vrtSelectedItem
End If
'Set object variable to Nothing
Set iFileSelect = Nothing
End Sub
The above gives a runtime error 5 when FilterType = 2 ?
However, the above works if I do:
Elseif FilterType = 2 then
iFileSelect.Filters.Add "User files", "*.h"
EndIf
But I need it to filter files only starting with "User" ... so all files like : "User*.h" ???
Is there straight forwards approach to this?
Thanks all in advance for your help!
Rn
Bookmarks