TriAxisZero
New Member
- Joined
- Nov 15, 2014
- Messages
- 11
I have a simple macro using the file dialog, the problem i'm having is the dialog is not executing the filters when opened.
When run this sub the dialog opens, filter 1 is active, but is not filtering the file list & the button caption is wrong, reading "Open" instead of "Import".
if i select a file the button caption changes, but the filter is still not working.
If i change the filter it works, including if i change in back to the first filter which should be active when opening.
any ideas?
Code:
Sub GetFieldFile()
Dim Getfile As FileDialog
Dim projnum As String
projnum = "\" & Home.Range("Project_Number").Value & "*.txt"
Set Getfile = Application.FileDialog(msoFileDialogFilePicker)
With Getfile
.Filters.Clear
.Filters.Add "Field Files", "*.txt;*.csv", 1
.Filters.Add "Text Files", "*.txt", 2
.Filters.Add "CSV Files", "*.csv", 3
.FilterIndex = 1
.Title = "Select a File"
.ButtonName = "Import"
.InitialFileName = "X:\SDSKPROJ\_Dump-" & Format(Now(), "YYYY") & projnum
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then
Debug.Print .SelectedItems(1)
ImportFieldData (.SelectedItems(1))
End If
End With
End Sub
When run this sub the dialog opens, filter 1 is active, but is not filtering the file list & the button caption is wrong, reading "Open" instead of "Import".
if i select a file the button caption changes, but the filter is still not working.
If i change the filter it works, including if i change in back to the first filter which should be active when opening.
any ideas?