Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting worksheet data to text file

Status
Not open for further replies.

Clairvoyant1332

Programmer
May 21, 2003
147
US
I'm trying to get the contents of an Excel worksheet exported to a text file, but the default formatting isn't what I'm looking for. Is there some way to open an external file so I can loop through the cells and write the data the way I want it, or should I be using some other method?

Dennis
 
Clairvoyant...

I am NOT.

Please explain what method of exporting Excel data to a text file is NOT working.

;-)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Sorry... I guess I wasn't too clear on the problem. I was unsure if the VB6 file statements (open,print,close) also worked under VBA, but I've since found that they do.

That's what I get for not RTFM closely enough... [hammer]
 
Here's hoping I'm posting correctly!
I'm looking for how you were able to export your excel data to txt using VBA.

Thanks
 
Code:
dim xcell as integer, ycell as integer
Open "c:\outputfile.txt" For Output As #1
xcell = 1
Do While Cells(xcell, 1) <> ""
  for ycell = 1 to {some number}
    Print #1, Cells(xcell, ycell)
  next ycell
  xcell = xcell + 1
loop
close #1
 
My code snippet does make a few assumptions about the data. I don't know offhand how to tell that you're definitely at the end of the data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top