Loading
ExcelRibbon.Tips.Net ExcelTips (Ribbon 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: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier 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 (8321) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Getting Rid of Extra Quote Marks in Exported Text Files.

Related Tips:

Save Time! ExcelTips has been published weekly since late 1998. Past issues of ExcelTips are available in convenient ExcelTips archives. Have your own enhanced archive of ExcelTips at your fingertips, available to use at any time! Check out ExcelTips Archives today!

 

Comments for this tip:

PhilP    29 Jul 2014, 13:22
I added 3 lines of code to the above macro which removes the need to highlight the range before removing the extra quote marks.

Open "I:\UnQuoted WinAmp Tags.csv" For Output As #1 is my output file.

Next I added new lines:

Windows("Edit WinAmp Tags.csv").Activate
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select

before:

For Each r In Selection.Rows

which makes my target datasheet active and selects anything in column A

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 3+4? (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

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–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.