Archive of Mr Excel Message Board
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?

| Check out our Excel VBA Resources | ||||
![]() |
![]() |
![]() |
![]() |
![]() |
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

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

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

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

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
