Olschi
Olschi

Reputation: 11

three quotation marks in from Excel (VBA) exported .txt-file

I have the following problem: To save the Worksheet in a .txt file, I wrote this sub:

Sub SaveFile()

Dim ans As Long
Dim sSaveAsFilePath As String
Dim VPname As String

VPname = Worksheets(3).Cells(2, 1)

    On Error GoTo ErrHandler:

    sSaveAsFilePath = ActiveWorkbook.Path & "\" & VPname & ".txt"

    If Dir(sSaveAsFilePath) <> "" Then
        ans = MsgBox("Datei " & sSaveAsFilePath & " existiert bereits.  Überschreiben?", vbYesNo + vbExclamation)
        If ans <> vbYes Then
            Exit Sub
        Else
            Kill sSaveAsFilePath
        End If
    End If
    Worksheets(3).Copy '//Copy sheet 3 to new workbook
    ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows '//Save as text (tab delimited) file
    If ActiveWorkbook.name <> ThisWorkbook.name Then '//Double sure we don't close this workbook
        ActiveWorkbook.Close False
    End If
MsgBox ("Worksheet wurde erfolgreich als txt-Datei gespeichert!")
My_Exit:
Exit Sub

ErrHandler:
MsgBox Err.Description
Resume My_Exit

End Sub

In this worksheet, the cells with text content have to have quotation marks (e.g. "example"). When I open the .txt-file, all these entrys have three quotation marks instead of one ("""example"""). Do you know how to fix this? Thanks a lot :)

Upvotes: 1

Views: 1229

Answers (1)

Vityata
Vityata

Reputation: 43595

Welcome to stackoverflow! It is really useful, to make a small question, that is replicable by the others - read more here - https://stackoverflow.com/help/mcve Thus, it would be easy for you to search as well.

In your case, a minimal and verifyable example would be like this:

Option Explicit

Public Sub TestMe()

    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\new1.txt", _
    FileFormat:=xlTextWindows

End Sub

Then, if you use the search engine, you would find that there is already some answer of it here:

Saving a Excel File into .txt format without quotes

:)

Upvotes: 1

Related Questions