Prompt user to Open file in VBA

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.
 
R

Ron de Bruin

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
 
F

Frank Kabel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top