Sorry, Norie. I'm not a big forum question asker, obviously. OK:
Sub GetImportFileName2(spath, UFileName)
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Dim i As Integer
Dim Msg As String
' Set up list of file filters
Filt = "Text Files (*.txt),*.txt," & _
"Comma Separated Files (*.csv),*.csv," & _
"Excel Files (*.xlsx),*.xlsx," & _
"All Files (*.*),*.*"
' Display *.xlsx by default
FilterIndex = 4
' Set the dialog box caption
Title = "Select a file to open:"
' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title, _
MultiSelect:=True)
' Exit if dialog box canceled
If Not IsArray(FileName) Then
MsgBox "No file was selected."
Exit Sub
End If
' Display full path and name of the files
For i = LBound(FileName) To UBound(FileName)
Msg = Msg & FileName(i) & vbCrLf
Next i
spath = Left(Msg, InStrRev(Msg, "\"))
MsgBox "Path: " & spath
UFileName = Mid(Msg, InStrRev(Msg, "\") + 1)
MsgBox "File: " & UFileName
End Sub
And it is called thusly:
Sub OpenGemsFile()
'
' Prompt for file and open
'
'
Dim Msg As String
Dim UFileName As String
Dim spath As String
ChDir ("c:\")
Call GetImportFileName2(spath, UFileName)
MsgBox spath
MsgBox UFileName
Workbooks.Open spath & UFileName
' Workbooks.Open FileName:="C:\Users\xxxxxx\Documents\Ramp Up Study\Ramp Up Study.xlsx"
End Sub
The MsgBox calls again show the correct path and filename.
Thanks!
Bookmarks