how do i make macro program on excell for create new txt file?

R

Richard

Hi all,

is there anyone can help me, I need make simple macro program.
I have a text file, inside this txt file there is certain code. Example
there is code 30 on line 10-15. I need a program that copy line 10-15 and
create a new file with the content only line 10 until 15 only. Thanks all
your help guys.

Best regards
 
T

Tom Ogilvy

Here is a link to sample code to read and write delimited files:

http://www.cpearson.com/excel/imptext.htm import/export text files

here is sample code to read in a text file:

Sub ReadStraightTextFile()
Dim sStr as String
Dim LineofText As String
Dim rw as Long
rw = 0
Open "C:\FILEIO\TEXTFILE.TXT" For Input As #1
sStr = ""
Do While Not EOF(1)
Line Input #1, LineofText
sStr = sStr & lineofText
if len(sStr) >= 178 then
rw = rw + 1
cells(rw,1).Value = sStr
sStr = ""
End if
Loop
'Close the file
if len(sStr) > 0 then
cells(rw,1).Value = sStr
End if
Close #1
End Sub

Here are other sources of information:


http://support.microsoft.com/default.aspx?scid=kb;en-us;151262
Working with Sequential Access Files

http://www.applecore99.com/gen/gen029.asp
 

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