creating text files.


Posted by Jason Davis on June 22, 2000 12:42 PM

I am using Excel to control a various hardware devices
and need to be able to stay in my original excel application.

how do i select a range of cells from a worksheet and save it as text file while not changing from my original excel document.
I have tried creating a word document from the sheet and then saveas text only, but it will not save as text only from excel. Maybe, if I could execute a word macro from an excel macro, or just plain save as text document.

Any Ideas?

Posted by Ivan Moala on June 27, 0100 1:32 AM

Try this mode (Untested !)

Sub WriteRangeCellsText()
Dim MyRg As Range
Dim TextCell As Range
Dim TxtToWrite As String

Set MyRg = Range("a1:D1")
For Each TextCell In MyRg
TxtToWrite = TxtToWrite & TextCell.Text & chr(13)
Next
Open "C:\Windows\Desktop\Test.txt" For Output As #1
Print #1, TxtToWrite
Close #1

End Sub

Ivan

Posted by Jason Davis on June 26, 0100 5:20 AM

Thank you for the information, I still have one problem, the text file is being generated now but the format needs to be changed.
all the data is put on one line such as
xxxxyyyyxxxxyyyy

but I need it in the following format

xxxx
yyyy
xxxx
yyyy
xxxx
yyyy

ect.....

Jason

Posted by Jason Davis on June 26, 0100 5:21 AM

Thank you for the information, I still have one problem, the text file is being generated now but the format needs to be changed.
all the data is put on one line such as
xxxxyyyyxxxxyyyy

but I need it in the following format

xxxx
yyyy
xxxx
yyyy
xxxx
yyyy

ect.....

Jason

Posted by Jason T. Davis on June 29, 0100 11:29 AM

Thank you again, after testing the program below
I changed the "char(13)" to "vbCrLf" and It gave
me the format that I needed.
Thank you for the information

Sub WriteRangeCellsText()
Dim MyRg As Range
Dim TextCell As Range
Dim TxtToWrite As String

Set MyRg = Range("a1:a65")
For Each TextCell In MyRg

TxtToWrite = TxtToWrite & TextCell.Text & vbcrlf

Next
Open "C:\Windows\Desktop\Test.txt" For Output As #1
Print #1, TxtToWrite
Close #1

End Sub



Posted by Ivan Moala on June 22, 0100 8:11 PM


Try something like this

Sub WriteRangeCellsText()
Dim MyRg As Range
Dim TextCell As Range
Dim TxtToWrite As String

Set MyRg = Range("a1:D1")
For Each TextCell In MyRg
TxtToWrite = TxtToWrite & TextCell.Text
Next
Open "C:\Windows\Desktop\Test.txt" For Output As #1
Print #1, TxtToWrite
Close #1

End Sub

This save the text in the set range as a sequential
ouput file to your desk top.
Change as neccesary


Ivan