Show Tab in Sep when Exporing to Txt

Miya

Well-known Member
Joined
Nov 29, 2008
Messages
662
Hi, in cpearson code to export txt file how do i show sep by tab, i tried using vbTab but when i saved it and opened via notepad it showed "vbTab"


http://www.cpearson.com/excel/ImpText.aspx

Sub DoTheExport()
ExportToTextFile FName:="C:\Test.txt", Sep:=";", _
SelectionOnly:=False, AppendData:=True
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi. Try without quotes

Code:
Sub DoTheExport()
ExportToTextFile FName:="C:\Test.txt", Sep:=vbTab, _
SelectionOnly:=False, AppendData:=True
End Sub
 
Upvote 0
Hi Vog, i have one more question regarding the below, i have my file path as a named range, how do i reflect this named range below, is it just as simple as this.

rngPath.txt

Hi. Try without quotes

Code:
Sub DoTheExport()
ExportToTextFile FName:="C:\Test.txt", Sep:=vbTab, _
SelectionOnly:=False, AppendData:=True
End Sub
 
Upvote 0
Try

Code:
Sub DoTheExport()
ExportToTextFile FName:=Range("rngPath").Value & ".txt", Sep:=vbTab, _
SelectionOnly:=False, AppendData:=True
End Sub
 
Upvote 0
That Worked, but i noticed when i run Cpearson code the text file does not overwrite previous version, so I have Test.txt saved in C:\Test\Downloads, but when i run the code twice it does not override the file, is there something in his code that stops overwriting?

Try

Code:
Sub DoTheExport()
ExportToTextFile FName:=Range("rngPath").Value & ".txt", Sep:=vbTab, _
SelectionOnly:=False, AppendData:=True
End Sub
 
Upvote 0
I'm not sure why it doesn't overwrite but you could always delete the existing file

Code:
Sub DoTheExport()
On Error Resume Next
Kill Range("rngPath").Value & ".txt"
On Error GoTo 0
ExportToTextFile FName:=Range("rngPath").Value & ".txt", Sep:=vbTab, _
SelectionOnly:=False, AppendData:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,835
Members
452,947
Latest member
Gerry_F

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