Code:
Public Function GetCSVFile(strPath As String) As String
'----------------------------------------------------------------------------------
'Requires reference to Microsoft Office 12.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim Forname As String
Forname = "ConFedFm"
Dim FuncTemp As String
'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box.
.AllowMultiSelect = False
.InitialFileName = strPath
'Set the title of the dialog box.
.Title = "Please select a file"
'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "csv files", "*.csv"
'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
Debug.Print "strPath = "; strPath; " .SelectedItems(1) = "; .SelectedItems(1)
strPath = .SelectedItems(1)
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
If strPath <> "" Then GetCSVFile = strPath
If strPath = "" Then GetCSVFile = ""
End Function
The above code used to work. Suddenly it started giving 13 type missmatch at the line where strPath = .SElectedIteems(1)