Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Writing a macro in Excel that Refreshes External Imported Text File | Excel Programming | |||
writing to text file | Excel Programming | |||
Writing to a text file | Excel Programming | |||
Writing to a text file | Excel Programming | |||
Writing a text file from Excel using VBA ... a small issue | Excel Programming |