Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default HELP! Writing Text file from Excel Spreadsheet.

Rick I found this on net as it says it will write and output nothing for a
blank. Thats my idea to eliminate all blank lines from excel worksheet.
Problem not knowing.
First Set fswrite variable not defined
put in dim statement
then
write path name varailable not defined
Here is code could you look and see what I am missing. This is a first for me.
Thanks in advance.

'The code below will write a CSV file and will not output anything for a
blank line
Sub WriteCSV()
Dim fswrite As Variable
Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"
Const Delimiter = ","
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set fswrite = CreateObject("Scripting.FileSystemObject")-------------
'open files
' WritePathName = MyPath + WriteFileName------------
WritePathName = "c:\temp\text.cvs" ----(tried this)
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)

lastrow = Cells(Rows.Count, "A").End(xlUp).row

For RowCount = 1 To lastrow
lastcol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
For ColCount = 1 To lastcol
If ColCount = 1 Then
OutputLine = Cells(RowCount, ColCount)
Else
OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
End If
Next ColCount
OutputLine = Trim(OutputLine)
If Len(OutputLine) < 0 Then
tswrite.writeline OutputLine
End If
Next RowCount

tswrite.Close

End Sub









"Rick Rothstein (MVP - VB)" wrote:

How do you want the text file to look? By that I mean, do you want every
cell on its own line in the file? Or do you want to keep the entire row
together on a single line in the file? If the latter, what delimiter do you
want between each cell's value? The more detail you can give as to what the
file should look like when the macro is finished, the better able we will be
to give you a solution.

Rick


"Curt" wrote in message
...
not smart enough. Have been trying to get your code to write more than 1
column. Also have been having trouble accessing this web site. Need to
write
A!:F50 to text file so can speed up mail merge. Have been told this will
eliminate word searching full sheet. Had on responce to this and all I get
when trying to acess is blank page. I got here by going into word then
getting here. any Help greatly appreciated.
Thanks



"Rick Rothstein (MVP - VB)" wrote:

You can use this macro to write out Column A's content...

Sub SaveColumnA()
Dim X As Long
Dim FF As Long
Dim ColumnText As String
For X = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
ColumnText = ColumnText & Range("A" & CStr(X)).Value & vbCrLf
Next
FF = FreeFile
Open "c:\temp\test.txt" For Output As #FF
Print #FF, ColumnText
Close #FF
End Sub

Rick


"JEB" wrote in message
...
Pardon my sence of urgency here, but I'm stuck and need help.
I have a worksheet that contains only one column of string data that I
need
to write to an MS-DOS formated Text file on my PC (for later use).
What
is
the simplest way to do it. (The data resides in colmun "A" and contains
anywhere from 50 to 160 rows).
Thanking you in advance.
JEB




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
Writing a macro in Excel that Refreshes External Imported Text File [email protected] Excel Programming 0 August 17th 07 08:29 PM
writing to text file ADK Excel Programming 7 July 13th 07 06:13 PM
Writing to a text file scantor145[_9_] Excel Programming 6 June 30th 05 08:23 PM
Writing to a text file Rachel Curran Excel Programming 0 October 8th 04 09:44 AM
Writing a text file from Excel using VBA ... a small issue ajames54 Excel Programming 3 December 3rd 03 03:35 PM


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

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

About Us

"It's about Microsoft Excel"