Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel97 - User Selects File For Code To Open 1

Status
Not open for further replies.

SHardy

Programmer
May 9, 2001
231
GB
I have an Excel97 workbook which I need to copy data to from a text file. This text file is to be opened
as fixed width with specific parameters.

Easy enough when you know the name and path of the file that you are opening.

However, the text files are created and named by the user (downloaded from a mainframe system). Therefore
they could be saved anywhere with anyname.

I don't want the user to have to type the name and path into the workbook prior to running the code.

I can't use the

Application.Dialogs(xlDialogOpen).Show ("C:\")

method, as this would then require the user to choose the file type and parameters.

Is it possible to display the file open dialog, for specific file type(s) and at a specified start directory,
and for no other action to be carried out other than passing the path and filename back to a variable?

Any help would be most appreciated.
 
Try this...

' Set desired path.
ChDir "C:\My Documents\"
' Replace the *.txt in the next line with YOUR selection criteria.
Filename = Application.GetOpenFilename(fileFilter:="Downloaded files, *.txt")
' You can then parse "Filename".

 
Thank you. I wasn't aware of this method, and it does exactly as I wanted.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top