Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / April 2008

Tip: Looking for answers? Try searching our database.

Write text data to text file without quotes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard - 28 Jan 2008 17:04 GMT
The standard write command encloses text data within quotes.
I need to create text file file that looks lie this:
       [category]
       x = Hi

But, for example, that following commands:
     Open text.txt for output as #1
      x = "Hi"
     Write #1, x
Produces a text file with line: "Hi"

How do I write a macro that produces a text file with text data that is not
enclosed  by quote marks?

Signature

Richard

Joel - 28 Jan 2008 17:11 GMT
When you write CSV data after opening a file using file number #1 excel adds
the extra quotes.  You need to open the file using a scripting language open
and writes.

Here is an example file

Sub WriteCSV()

Const Delimiter = ","

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const MyPath = "C:\temp\"
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
   

Set fswrite = CreateObject("Scripting.FileSystemObject")
   
WriteFileName = "text.csv"

  'open files
  WritePathName = MyPath + WriteFileName
  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
     If Range("D" & RowCount) > Date Then
        For ColCount = 1 To 12
           If ColCount = 1 Then
              OutPutLine = Cells(RowCount, ColCount)
           Else
              OutPutLine = OutPutLine & Delimiter & Cells(RowCount, ColCount)
           End If
        Next ColCount
        tswrite.writeline OutPutLine
     End If
  Next RowCount
     
  tswrite.Close
 
End Sub

> The standard write command encloses text data within quotes.
> I need to create text file file that looks lie this:
[quoted text clipped - 9 lines]
> How do I write a macro that produces a text file with text data that is not
> enclosed  by quote marks?
Dave D-C - 28 Jan 2008 21:16 GMT
Hmm, I want to look at scripting.
But merely using
 PRINT #1, ..
should give him what he wants.  Dave D-C

>When you write CSV data after opening a file using file number #1 excel adds
>the extra quotes.  You need to open the file using a scripting language open
[quoted text clipped - 53 lines]
>> How do I write a macro that produces a text file with text data that is not
>> enclosed  by quote marks?
Curt - 28 Apr 2008 17:41 GMT
I've never created a text file before. Your code looks like it may be my
answer. Not sure. What I want to accomplish is to copy (A:E) or (A:F) and use
xls.end up to stop at last row. This is to limit the size of text file to
only data entered. I will then use the text file for a mail merge. Trying to
merge off excel sheet is to slow. Any I will try to comprehend what you have
here. Any assistance greatly appreciated.
Thanks in Advance. What is CSV?

> When you write CSV data after opening a file using file number #1 excel adds
> the extra quotes.  You need to open the file using a scripting language open
[quoted text clipped - 53 lines]
> > How do I write a macro that produces a text file with text data that is not
> > enclosed  by quote marks?
Rick Rothstein (MVP - VB) - 28 Apr 2008 19:43 GMT
For whatever reason, my newsreader is not showing me any of the thread you
are responding to, so all I see is what is quoted within your response. In
that quoted section, Richard uses Open/Output to open a channel and then
Write to put text into the file for that channel... and then asks if there
is a way to put that text in the file without the quote marks. Rather than
the FileSystemObject method Joel proposed (also shown in your quoted text),
I would have suggested to the OP to continue using Open/Output, but to use
Print #1 rather than Write #1 to eliminate the quote marks around text
strings when placing his text into the file.

Rick

> I've never created a text file before. Your code looks like it may be my
> answer. Not sure. What I want to accomplish is to copy (A:E) or (A:F) and
[quoted text clipped - 67 lines]
>> > not
>> > enclosed  by quote marks?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.