View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Reads entire *.txt file into string opposed to a desired line by line input.

Hi Edward,

ej_user wrote:
I have a text file of html source code (acquired using openurl) that I
want to read into Excel through VBA. My problem in the entire file is
read into a string; I want to evaulate the file line by line.

The text file contains a character that resembles a rectangle standing
on end that is understood in Wordpad as a carraige return - i think.
If I open the source code text file in Wordpad and save it as a DOS
text file, I can read the file just fine in Excel using VBA. How can
I programmatically resolve this issue?


You should be able to use the Split function with a vbCrLf delimeter.
Here's an example using IE automation:

Sub Demo()
Dim ie As Object
Dim sWholeFile As String
Dim asLineByLine() As String
Dim lLine As Long

Set ie = CreateObject("InternetExplorer.Application")

ie.Navigate "http://www.longhead.com/"

Do While ie.Busy And Not ie.ReadyState = 4
DoEvents
Loop

sWholeFile = ie.Document.body.innerhtml
ie.Quit
Set ie = Nothing
asLineByLine = Split(sWholeFile, vbCrLf)

For lLine = LBound(asLineByLine) To UBound(asLineByLine)
Sheet1.Cells(lLine + 1, 1).Value = asLineByLine(lLine)
Next lLine
End Sub


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]