Thread: Macro help
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Macro help

fname = Application.GetOpenFileName()
fname will either be False or contain the fully qualified path of the file
the user selected using the file open dialog.

It does not open the file. You can now use the information to open the file

This is what you asked for.

See help on the GetOpenfileName method for optional arguments and a further
explanation.

Where you had

workbooks.open "C:\Myfiles\Myfile.xls"

you would now have
Dim fName as String
fname = Application.GetOpenFileName()
if not fname = "False" then
workbooks.Open fName
Else
Exit sub
end if

as an example

--
Regards,
Tom Ogilvy
"tim" wrote in message
...
I'm new to the use of macro. I recorded a macro to get
external data, with defined ranges and fields from one of
many files that contain the exact same format of data.
Works great but I want to be able to select the file to
get the data from in the macro. Can the macro be edited
to do this?