LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Help with Open and Read txt file, please?

Ed,

You might have to declare another variable to refer to a Text Stream object,
then include an additional line of code to open the file that way. Also, you
should use the AtEndOfStream property on the Text Stream object to prevent
running past the end of the file. Also, how do you plan to read multiple
lines of text file into a single Contents variable? Each line would probably
have to be added with a NewLine string (vbNewLine) (or vbCrLf) embedded
between it and the previous contents.

So your code (untested revision) might look like the following:

Dim FSO As Object, File As Object, Contents As String
Dim TS as Object
'Text Stream object.
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim strFName As String
Dim strFPath As String
strFPath = ActiveWorkbook.Path & "\"
strFName = strFPath & "About.txt"

Set File = FSO.OpenTextFile(strFName)
Set TS = File.OpenAsTextStream(1, 0) 'Open the text file for reading in
ASCII format.

Contents = ""
Do While Not TS.AtEndOfStream
Contents = Contents & TS.ReadLine & vbNewLine
Loop

TS.Close

'Now do something with Contents.
--
Regards,
Bill


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FILE CAN ONLY OPEN AS READ ONLY vcff Excel Discussion (Misc queries) 2 November 18th 08 11:18 AM
Excel file won't open because it' a read only file when it is not IanB Excel Discussion (Misc queries) 1 September 12th 05 01:28 PM
How to Open file as read only Helen Excel Programming 1 January 24th 05 02:45 PM
Open File Read Only Chris Excel Programming 1 September 23rd 04 12:11 AM
File in use open read only jeffP Excel Programming 0 August 21st 04 06:37 PM


All times are GMT +1. The time now is 09:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"