Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Exporting Text File

Hello all

I am writing an Excel macro for exporting worksheet data into text file.
However, both statements "PRINT #" and "WRITE #" exports text in delimited
format (i.e. Chr(13) + Chr(10) added at the end each time these statements
are used). How can I get rid of the Chr(13) + Chr(10) codes?

Thanks in advance.

Raymond Lee


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Exporting Text File

You could do something like:

Sub testme01()

Dim iRow As Long
Dim iCol As Long

Open "textfile.txt" For Output As #1

With ActiveSheet
For iRow = 1 To 10
For iCol = 1 To 5
Print #1, .Cells(iRow, iCol).Value; ",";
Next iCol
Next iRow
End With
Close 1

End Sub

And all the output data is one line.

But maybe you were looking for something like:

Option Explicit
Sub testme02()

Dim iRow As Long
Dim iCol As Long
Dim myStr As String

Open "textfile.txt" For Output As #1
With ActiveSheet
For iRow = 1 To 10
myStr = ""
For iCol = 1 To 5
myStr = myStr & "," & .Cells(iRow, iCol).Value
Next iCol
myStr = Right(myStr, Len(myStr) - 1)
Print #1, myStr
Next iRow
End With

Close 1

End Sub

This'll put each row on a separate line.

You may want to look at how Chip Pearson implemented a version:
http://www.cpearson.com/excel/imptext.htm

And Earl Kiosterud's Text Write program is available at:

It's available at Tushar Mehta's site:
http://www.tushar-mehta.com/
Look for Text Write in the left hand frame.

Earl has a bunch of options (including, IIRC, wrapping each cell in double
quotes)

You may find some of the ideas in each useful.

Ray Ray wrote:

Hello all

I am writing an Excel macro for exporting worksheet data into text file.
However, both statements "PRINT #" and "WRITE #" exports text in delimited
format (i.e. Chr(13) + Chr(10) added at the end each time these statements
are used). How can I get rid of the Chr(13) + Chr(10) codes?

Thanks in advance.

Raymond Lee


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 July 1st 05 03:04 AM
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 June 29th 05 05:26 AM
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 June 22nd 05 11:26 PM
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 June 22nd 05 05:33 AM
Exporting from Excel to a text file Josh Brien Excel Discussion (Misc queries) 3 May 20th 05 09:54 PM


All times are GMT +1. The time now is 04:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"