ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening text files (https://www.excelbanter.com/excel-programming/387513-opening-text-files.html)

Dan R.

Opening text files
 
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


Jim Rech

Opening text files
 
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
"Dan R." wrote in message
oups.com...
|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
|



urkec

Opening text files
 
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

--
urkec


"Jim Rech" wrote:

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
"Dan R." wrote in message
oups.com...
|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
|





All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com