Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

write to text files

  Asked By: Annie    Date: Jan 01    Category: MS Office    Views: 670
  

I need to read from a text file and then write to another text file.Is there
any way i could do it using excel.I tried using streamrecorder but not able to
figure out the vba refernces library i need to enable.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Laura Rodriguez     Answered On: Jan 01

In Excel, turn macro recorder on
do your stuff
ie open text  file
save text file  as
end recorder

Examine the code

 
Answer #2    Answered By: Spiru Kelly     Answered On: Jan 01

I have the following contents in a text  file
5 6
7 8
9 1
2 3
4 6
1 3
4 6
4 7
4 6

the file  is also saves as nos.txt , saved under
"C:\Documents and Settings\Birumanand\Desktop\"

This should work...

Sub Read_write()

Dim iPath As String
Dim iRunner As Long

iPath = "C:\Documents and
Settings\Birumanand\Desktop\"

X = 0
Open iPath & "nos.txt" For Input As #1

Line Input #1, St

While Not EOF(1)
X = X + 1
Sheets(1).Cells(X, 1) = Left(St, 1)
Sheets(1).Cells(X, 2) = Right(St, 1)

Line Input #1, St


Close #1


Open iPath & "output.txt" For Output As #1

For iRunner = 1 To
Sheets(1).Cells.SpecialCells(xlCellTypeLastCell).Row()

Print #1, Trim(Sheets(1).Cells(iRunner, 1) *
Sheets(1).Cells(iRunner, 2))

Next


Close #1

End Sub


let me know, is that what you were looking for...

 
Didn't find what you were looking for? Find more on write to text files Or get search suggestion and latest updates.




Tagged: