How to export Excel data to Text files in Excel?

If you are required to deliver a workbook in the format of text file, you need to convert the workbook into text files. And this article will introduce you two methods to export Excel data into text files easily.

Export Excel data to text files with the Save As command

Export selected range or worksheet to text file with VBA code

Export selected range or worksheet to text file with Kutools for Excel

Recommended Productivity Software

Office Tab: Use tabbed interface in Office as the use of web browser Chrome, Firefox and Internet Explorer.
Kutools for Excel: Adds 120 powerful new features to Excel. Increase your productivity in 5 minutes. Save two hours every day!
Classic Menu for Office: Brings back your familiar menus to Office 2007, 2010 and 2013 (includes Office 365).

arrow blue right bubble Export Excel data to text files with the Save As command

Hint


By default, the Excel data will be saved as workbooks in the format of .xlsx. However, we can export a worksheet of existing workbook as text files with the following steps:

Step 1: Click the Save as button under File tab in Excel 2010; in Excel 2007 click the Office Button and Save as button;

Step 2: Save As dialog box comes out. Name the file in the File name text box and select the folder that you will save the file in;

Step 3: In the Save as type drop down list, select the Unicode Text . See screenshot:

doc-data-to-text-1

Step 4: Then it will pop up two warning dialog boxes asking you to export only active worksheet as text file and leave out any incompatible features with text file. Click OK and Yes.

doc-data-to-text-2
-1
doc-data-to-text-3

Then the data in the active worksheet are exported as a new text file.

Note: the Save As command is only able to export data of active worksheet as a text file. If you want to export all data of the whole workbook, you need to save each worksheet as a text file individually.


arrow blue right bubble Export selected range or worksheet to text file with VBA code

The following VBA code also can help you to export the selected range data or entire worksheet to the text file, please do as this:

Step 1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

Step 2. Click Insert > Module, and paste the following code in the Module Window.

VBA: export selection or entire worksheet to text file

Sub ExportRangetoFile()
'Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Step 3. Then press F5 key to run this code, and a prompt box will pop out to tell you to select the data range that you want to export, see screenshot:

doc-data-to-text-4

Note: If you want to export the entire worksheet, in the above prompt box, hold down the Ctrl + A keys.

Step 4. Then click OK, and specify a name for this text file and a folder to put this file in the popped out Save As dialog.

doc-data-to-text-5

Step 4. Then click Save button, and the selected data range has been exported as text file.


arrow blue right bubble Export selected range or worksheet to text file with Kutools for Excel

The Save As command can export all data in the active worksheet as text. What if exporting all data of specified inactive worksheets, or part of the data in a worksheet as a text file? Kutools for Excel's Export Range to File tool can help us export and save the data in any worksheet as text file easily no matter it is active or not.

Kutools for Excel includes more than 120 handy Excel tools. Free to try with no limitation in 30 days. Get it Now.

After installing Kutools for Excel, please do as following steps:

Step 1: Click Enterprise > Import / Export > Export Range to File, see screenshot:

doc-data-to-text-6

Step 2: In the Export Range to File dialog box, do following options:

  • (1.) Click the doc-data-to-csv-6 button to select a range that you want to export its data as a text file. If you want to export the entire worksheet, after clicking the doc-data-to-csv-6 button, then hold down the Ctrl + A keys.
  • (2.) Then check the Unicode Text option under File format, and then choose the text options as you need, see screenshot:

doc-data-to-text-7

Step 3: Then click OK, and specify a name and a location for the exported range file.

doc-data-to-text-8

Step 4: And then click Save, now the selected range is exported as a new text file. See screenshot:

doc-data-to-text-9

Kutools for Excel's Export Range to File tool makes it possible to easily export a range of date to a file, either an Excel workbook, a CSV, a simple HTML or all formatting HTML.

arrow blue right bubble Related Articles:


Is your problem solved?

Recommended Productivity Tools

The following tools will greatly save your time and effort, which one do you prefer?
Office Tab: Using handy tabs in your Office, as the way of Chrome, Firefox and New Internet Explorer.
Kutools for Excel: 120 powerful new functions for Excel, Increase your productivity in 5 minutes. Save two hours every day!
Classic Menu for Office: Bring back familiar menus to Office 2007, 2010, 2013 and 365, as if it were Office 2000 and 2003.

Kutools for Excel

gold star1 Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1 More than 120 powerful advanced functions which designed for Excel:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more     btn download     btn purchase