Opening text files

D

Dan R.

I have an application that prompts the user to select a text file for
processing which is done by using the 'GetOpenFilename' from the
Microsoft Excel object library. I'm not using Excel in the program
so
I'm assuming this is probably not the best way to do this. Any
suggestions?

inputfile = Application.GetOpenFilename( _
fileFilter:="Text Files (*.txt),*.txt", _
Title:="Select the file")

Thanks,
-- Dan
 
J

Jim Rech

I agree that using the Excel object model just for GetOpenFilename seems
overkill and requiring a user to have Excel installed for no other reason is
to be avoided.

Another approach is to use the Windows API. The downside is that it is a
lot more complex. This site has code specifically for standalone VB6 but
you could adapt it to VBA pretty easily I think.


http://vbnet.mvps.org/code/comdlg/fileopendlg.htm

--
Jim
|I have an application that prompts the user to select a text file for
| processing which is done by using the 'GetOpenFilename' from the
| Microsoft Excel object library. I'm not using Excel in the program
| so
| I'm assuming this is probably not the best way to do this. Any
| suggestions?
|
| inputfile = Application.GetOpenFilename( _
| fileFilter:="Text Files (*.txt),*.txt", _
| Title:="Select the file")
|
| Thanks,
| -- Dan
|
 
U

urkec

On XP systems you could try something like this:

Sub openTXT()

'XP only
Set cd = CreateObject _
("UserAccounts.CommonDialog")

cd.Filter = "Text Files|*.txt"
cd.InitialDir = "C:\"
If cd.ShowOpen = 0 Then
Exit Sub
End If

Debug.Print cd.Filename

End Sub
 

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