Prompt user to Open file in VBA

  • Thread starter Thread starter Nick
  • Start date Start date
N

Nick

Is it possible to prompt the user to Open a file while a
macros is running and then to continue the macro once the
file selected is opened.

Instead of:
Workbooks.Open Filename:= "\\traders\0104.xls"

I would like to allow user to pick the file that opens and
have the macro continue after the file has been selected.

Thank you for any help that can be provided.
 
Look in the VBA help for GetOpenFilename

Sub test()
Dim FName As Variant
Dim wb As Workbook
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName <> False Then
Set wb = Workbooks.Open(FName)
MsgBox "your code"
wb.Close
End If
End Sub
 
Hi Nick
try the following:
Sub test_fileopen()
Dim filename
filename = Application.GetOpenFilename
If filename <> False Then
Workbooks.Open (filename)
MsgBox "Continue"
' add your code here
End If
End Sub

Frank
 
Back
Top