Exporting to a multiline flat text file.


Posted by Andy Gee on January 08, 2002 2:29 AM

I've been banging my head against the wall for almost 5 minutes now!
Say A1 = 1, A2 = 2, A3 = 3 etc.
I need to find a way to export a range of cells into a text file and make a new line for each cell. So the text file would look like this:

1
2
3
4
5

Any help please!

Posted by Bruno on January 08, 2002 3:00 AM

Scroll down 1 or 2 pages and you will find the question :
Exporting data to a text file - John 17:11:03 01/07/02
With the following solution :
13112.html - Ivan F Moala 22:18:38 01/07/02 (0)

The code of Ivan has a module to write and a module to read the text file...

Bruno
-----

Posted by Andy Gee on January 08, 2002 3:25 AM

I only need to add a line break after each record and I can't figure out which part of the macro does it.

Posted by Bruno on January 08, 2002 3:41 AM

See next code : every time you use
"Print #1, TxtToWrite" a line feed is autom. added...

Example 1
When you use :
Print #1, A
Print #1, B
Print #1, C

This is the result :
A
B
C
=========
Example 2
When you use :
Print #1, A,B,C

This is the result :
A B C


Bruno
-----

Sub WriteRangeCellsText()

Set MyRg = Range("A1:A5")

Open "C:\Windows\Desktop\Test.txt" For Output As #1
For Each ocell In MyRg
TxtToWrite = ocell.Text
Print #1, TxtToWrite
Next
Close #1

End Sub

Posted by Andy Gee on January 08, 2002 3:51 AM

Re: You the man Bruno!!!

Thanks to you, I have now finished a project I have given 17hrs a day for the last 4 days. I can eat now!


I can see that coming in very usefull in the future too!



Posted by Bruno on January 08, 2002 4:46 AM

Enjou your meal, but...

The real guy to thank is Ivan F Moala

He posted the code before...
I'm only the midget to explain a few things ;-)

Bruno
-----