View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
moondark[_5_] moondark[_5_] is offline
external usenet poster
 
Posts: 1
Default insert text to a specific cell


You need three code segments:

Open and Close file:

Code
-------------------
Public Sub open_textstream(path as string)
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.GetFile(path)
filesize = file.Size 'wird im Moment nicht benötigt
Set ts = file.OpenAsTextStream(1, -2)
End Sub
Public Sub close_textstream()
ts.Close
End Su
-------------------


Startbutton called Start with following code

Code
-------------------
private sub start_click()
call open_textstream("C:\test.txt")
call main
call close_textstream
end su
-------------------


Main Procedure filling the Cells:

Code
-------------------
sub main()
do while ts.endofstream <""
data = ts.readline()
dat = split(data,chr(9))'i think chr(9) was TAB
for i = 0 to ubound(dat())
Cells(countrows+3,i+7) = dat(i)
next i
countrows = countrows + 1
loop
end su
-------------------



don't know if it works perfectly (written in about 1 minute ;))
Simo

--
moondar
-----------------------------------------------------------------------
moondark's Profile: http://www.excelforum.com/member.php...fo&userid=2739
View this thread: http://www.excelforum.com/showthread.php?threadid=47017