Excel: Macro to Save Data as Tab-Delimited File without QuotesLast reviewed: June 30, 1997Article ID: Q104997 |
The information in this article applies to:
SUMMARYIn Microsoft Excel, to save a selection of data as a tab-delimited text file, select the Text file format in the Save File As Type box in the Save As dialog box. When you save a file in this format, if any of the cells in the spreadsheet contain commas, quotation marks, or other characters that could be misinterpreted when you reopen the file, Microsoft Excel encloses those values in quotation marks. If you want to create a tab-delimited text file and you do not want these additional quotation marks to be added, you must use a macro to save the data to a text file.
MORE INFORMATIONMicrosoft provides macro examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This macro is provided as is and Microsoft in no way guaranties that the following code can be used in all situations and will not support modifications of the code to suit specific customer requirements. To create a tab-delimited text file without enclosing text strings in quotation marks:
CAUTION: Any existing files with that same name will be overwritten by the new text file.
Explanation of macroA1: Macro name A2: Initialize a variable "nextcol" equal to zero A3: Open a sequential file for write access using user-provided name stored in "getname"A4: Initialize a variable "colcount" to number of columns in the selected rangeA5: Begin a FOR.CELL loop through the selected range A6: Check to see if current cell contains a number not formatted to GeneralA7: If the current cell meets above criteria, write current cell contents to file with formattingA8: Otherwise A9: Write current cell contents to file without formatting A10: End If clause A11: Increment "nextcol" A12: Check to see if end of current row in selection A13: Write return and line feed to file A14: Reset "nextcol" to zero A15: Otherwise A16: Write a tab character to file A17: End If clause A18: Go to next loop iteration A19: Close file on completion A20: End macro
|
Additional reference words: 4.00 4.0a 4.00a
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |