You could add a Browse for file button or simply ask the user within the code to select a file
Option Explicit
Sub openfile()
Dim sFil As String
Dim sTitle As String
Dim sWb As String
Dim iFilterIndex As Integer
On Error GoTo err_handler
' Set up list of file filters
sFil = "Excel Files (*.xls),*.xls"
' Display *.xls by default
iFilterIndex = 1
' Set the dialog box caption
sTitle = "Select File to Open"
' Get the filename
sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
Workbooks.Open Filename:=sWb
'rest of code here
Exit Sub
err_handler:
MsgBox "No selection made", vbCritical, "Cancelled"
End Sub
Bookmarks