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.

Getting Rid of Extra Quote Marks in Exported Text Files

Written by Allen Wyatt (last updated January 9, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


1

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.)

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Fixed-Width Settings when Converting Text to Columns

The Convert Text to Columns capabilities of Excel are very helpful when pulling apart information. When working with ...

Discover More

Saving in a Macro Using a Desired File Name

Need to save a new document, from within a macro, to a specific file name? If you use the Record Macro capabilities of ...

Discover More

Locking Paragraphs So They Cannot be Edited

Want to protect certain paragraphs in your document so they cannot be changed? This tip provides a look at three ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (menu)

CSV File Opens with Data in a Single Column

When you import a CSV file into an Excel worksheet, you may be surprised at how the program allocates the information ...

Discover More

Extracting File Names from a Path

If you have a full path designation for the location of a file on your hard drive, you may want a way for Excel to pull ...

Discover More

Full Path Names in Excel

Need to know what the full path name is for the current workbook? With a simple macro you can display the full path name ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 0?

2021-04-10 03:40:43

Rafael

Thank you a thousand times!! After searching for almost 6 hours for a solution, I finally end up on your website with this valuable tip. It finally works. Thanks for sharing your script.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.