Excel VBA Save as tab delimited file

I have a code that saves the active worksheet as a text file with tab delimiters, however the cell data that has a comma character is exported with quotes, for example

John Hopkins, Burgers
becomes
"John Hopkins, Burgers"

How can I get around this?

This is my code:

ActiveWorkbook.SaveAs ActiveWorkbook.path & "\" & filename,
FileFormat:=xlText, CreateBackup:=False

Adding this: I just found out that if I save the file again, it will delete everything "". Can I add extra save to code?

+4
source share
4 answers

I solved it! Because quotes disappear when you save them manually as a delimited file, but not when using

ActiveWorkbook.SaveAs ActiveWorkbook.path & "\" & filename,
FileFormat:=xlText, CreateBackup:=False

, , sendkey, .

ActiveWorkbook.SaveAs fil, FileFormat: = _       xlText

SendKeys "^{F4}"
SendKeys "{ENTER}"
SendKeys "{ENTER}"
+2

FileFormat Property :

xlCSV
xlCSVMac
xlCSVMSDOS
xlCSVWindows

?

xlCSV.

+1

, xlsb xls * .

Sub SaveAsTDV()

'
' Easy way to export to Tab Deliminated Values
' By DeLaguna
' v17.05.10.15.06
'

Dim BaseFolder As String
    Dim LitProg As String
    Dim Path As String
    Dim Extn As String
      BaseFolder = "YourBase Folder\"    
      FileName = "FileName" 'File name with no Extension.
      Extn = ".txt" 'If choosing somthing other than xlText you may change this.

 Application.DisplayAlerts = False 'Auto Yes to save

    ChDir BaseFolder
        ActiveWorkbook.SaveAs Filename:= BaseFolder & FileName & Extn, _
        FileFormat:=xlText, CreateBackup:=True  'xlText will save as Tab Deliminated text

Application.DisplayAlerts = True ' Reverts to Excel Default showing popup messages for input.

End Sub

, - , - , .

0

Change FileFormat xlText to xlTextPrinter

 ActiveWorkbook.SaveAs ActiveWorkbook.path & "\" & filename,
    FileFormat:=xlTextPrinter, CreateBackup:=False
0
source

Source: https://habr.com/ru/post/1656200/


All Articles