Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Getting Rid of Extra Quote Marks in Exported Text Files

Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Getting Rid of Extra Quote Marks in Exported Text Files.

Sometimes the export filters used by Excel can produce undesired results in the exported file. For instance, when you export to a tab-delimited text file, some Excel filters place quote marks around the text in a cell. For instance, assume that a particular cell contains the following text:

Create bts; sitemask = "0110"; pcmlink = 40 

This, however, is how the text in the cell is exported by Excel:

"Create bts; sitemask = ""0110""; pcmlink = 40" 

Notice that Excel adds extra quotation marks, first around the entire cell contents, and then an extra set around any previously "quoted" text within the cell.

One solution for handling the problem is to simply load the text file created by Excel into another program, such as Word, and use the Find and Replace feature to remove the undesired quotes. A better solution, however, is to create your own macro that creates the output text file. Consider the following macro:

Sub Export()
    Dim r As Range, c As Range
    Dim sTemp As String

    Open "c:\MyOutput.txt" For Output As #1
    For Each r In Selection.Rows
        sTemp = ""
        For Each c In r.Cells
            sTemp = sTemp & c.Text & Chr(9)
        Next c

        'Get rid of trailing tabs
        While Right(sTemp, 1) = Chr(9)
            sTemp = Left(sTemp, Len(sTemp) - 1)
        Wend
        Print #1, sTemp
    Next r
    Close #1
End Sub

All you need to do is select the cells you want to export, and then run the macro. The cells in the selection are extracted from the worksheet and placed in the file c:MyOutput.txt. (This filename can be changed in the macro to whatever your needs dictate.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2237) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Getting Rid of Extra Quote Marks in Exported Text Files.

Related Tips:

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Dave N    24 Apr 2016, 16:10
Marvelous! Thanks so much. Now in 2016 it's STILL a problem. And with a little 'Export' button added, linked to the macro, perfection!
Ben U    14 Jan 2016, 07:01
Brilliant, thank you
Sheila    28 Aug 2015, 14:53
Thank you!!!
Robert W    08 May 2015, 17:36
The easiest solution I have found is to just open the Excel spreadsheet and highlight what you want (even the entire spreadsheet) and then copy & paste it directly into NotePad.
Apoorv S    01 May 2015, 10:42
Thanks a lot.. I have been searching a solution for this issue for sometime now. This code worked like a charm.
Ishu    10 Mar 2015, 12:48
Hi! i am trying to use your suggestion. I am having a text file and I want to Output that using the VBA in MS Excel. When I use the Output command, I am getting a "Permission Denied: Error 70" error. I believe this is because I am trying to Output a write-protected text file. Can you suggest me the vba code required to remove the write-protection on this text file. This would help me a lot and I greatly appreciate it.
ACE    16 Dec 2014, 09:24
Amaising Macro
kavitha    19 Nov 2014, 04:52
Above code worked for my problem...Thank you...But small doubt what is WEND in the above code?
kavitha    19 Nov 2014, 02:26
If i convert excel file into csv, when i open that converted file in notepad it is showing some extra double quotes. how can i remove this quotes?
Mike    30 Oct 2014, 14:23
Or do it the easy way. Export the file as CSV. Edit it using Notepad. Remove all the Quotes and save it. Done.
john s    23 Jul 2014, 16:28
This is an excellent tip!
Paul    18 Jun 2014, 12:20
Also found a lot of crappy "solutions" on the internet, before this one!!! I new I had to do something with the [Print] command...
In addition, I only needed to start with replacing my existing qoutes:

    Cells.Replace What:="""", Replacement:="'", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Jen    26 Mar 2014, 16:34
Is there anyway to do this on just a single column within an existing macro?

I have an exported webpage in Excel that we run a lengthy macro on, but still has hidden quotations on only 1 column (G) that we manually find/replace via the text file.

I would like to be able to add this into the existing macro for column G only.

I'm teaching myself VB so I would appreciate any assistance!

Thanks!
Sam A    07 Nov 2013, 16:25
This worked great. Thanks!
One alteration I made was to open the file after saving it(at the very end). To do this I added the following code at the end(See full example below): Shell "notepad++.exe ""c:\temp\MyOutput.txt""", vbNormalNoFocus



Sub Export()
    Dim r As Range, c As Range
    Dim sTemp As String

    Open "c:\temp\MyOutput.txt" For Output As #1
    For Each r In Selection.Rows
        sTemp = ""
        For Each c In r.Cells
            sTemp = sTemp & c.Text & Chr(9)
        Next c

        'Get rid of trailing tabs
        While Right(sTemp, 1) = Chr(9)
            sTemp = Left(sTemp, Len(sTemp) - 1)
        Wend
        Print #1, sTemp
    Next r
    Close #1
    Shell "notepad++.exe ""c:\temp\MyOutput.txt""", vbNormalNoFocus
End Sub
Lisa    31 Oct 2013, 00:23
Thanks! This is great. Have been struggling with this for a couple of weeks and you have solved it!
Taylor    24 Sep 2013, 00:09
Thank you so freaking much for this elegant and effective macro! This page just ended two hours of frustrated google searches.
Bruno V    19 Aug 2013, 05:36
Hi, interesting tip. Excel also puts quotation marks around email addresses one wants to copy into the TO-line of Outlook when there is more than one email address in a cell. Can this macro be adapted to remove the quotation marks while transiting through the clipboard?
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.