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.
by Allen Wyatt
(last updated August 17, 2013)
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.
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!
Does your macro need to add information to the end of a text file? This is called appending, and is done using the technique ...Discover More
Want to easily control which records get imported from a text file into Excel? It's easy to do when you write the macro that ...Discover More
You can export an Excel worksheet in a variety of formats. One of those formats is Lotus 1-2-3, which is available as an ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.