Exporting data to Text (Tab Delimited)

Dilshan Anandan

New Member
Joined
Nov 14, 2018
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I am Trying to export a particular sheet to Text (Tab Delimited) File. The path to save the file and the name of the text file should be selected by the user.
I tried searching in internet and i am Fed up on this. I tried the below code but the whole workbook is getting saved in the selected path.
The Code I tried is -

Sub Savetxt()


Dim file_name As Variant
file_name = Application.GetSaveAsFilename(FileFilter:="Microsoft Excel file (*.txt), *.txt")
If file_name <> False Then
ActiveSheets.SaveAs Filename:=file_name
MsgBox "File saved!"
End If
End Sub

The text file getting saved is something like opening a excel file with text book.

If anyone could help on this, that would be great.
Thank you in advance

Dilshan
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Welcome to the Board!

It is not enough to change the file extension, you must also change the file type. Otherwise, it will just save it as an Excel file.
If you want to save it as a tab-delimited text file, you need to add this:
Code:
ActiveWorkbook.SaveAs Filename:=file_name[COLOR=#ff0000], FileFormat:=xlText[/COLOR]
Note: You can get this part of the code pretty easily by using the Macro Recorder. Just turn on the Macro Recorder and record yourself saving as a Tab-Delimited Text file. Then stop the Recorder and look at the code that you just recorded.
 
Upvote 0
Thank you for the help.
That really worked. And that was a good idea, to record and view the code.
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,205
Members
448,874
Latest member
Lancelots

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top