【问题标题】:How to prevent additional inverted comas duplicated when saving Excel file as txt将 Excel 文件另存为 txt 时如何防止额外的引号重复
【发布时间】:2021-10-21 17:06:10
【问题描述】:

我有一个要另存为文本的 Excel 文件,但我注意到具有双反逗号 (") 的单元格会复制双反逗号,并且这些单元格在开头/结尾处获得双反逗号文本。

例如

A1 = Cell with inverted coma (")
A2 = No Inverted coma

我正在使用以下代码:

Sheets("SO").Copy
Cells.Copy
txtFile = "C:\TextSO.txt"
ActiveWorkbook.SaveAs Filename:=txtFile, FileFormat:=xlUnicodeText
ActiveWindow.Close

我在txt文件中得到的输出如下:

"Cell with inverted coma ("")"
No Inverted coma

我也试过 FileFormat:=xlTextMSDOS 但没有区别

我还尝试创建一个添加行值的 txt 文件,但没有帮助。这是我使用的代码:

txtFile = "C:\TextSO.txt"
LR = ActiveSheet.Range("A1").Offset(ActiveSheet.Rows.Count - 1, 0).End(xlUp).Row
Open txtFile For Output As #1
For I = 1 To LR
    Write #1, Range("A" & I).Value
Next
Close #1

我得到的输出如下:

"Cell with inverted coma ("")"
"No Inverted coma"

关于我可以使用什么代码来防止添加额外的倒昏迷有什么想法吗?

【问题讨论】:

    标签: excel vba txt


    【解决方案1】:

    Write 加引号,所以使用Print

    Print #1, Range("A" & I).Value
    

    【讨论】:

    • 完美,谢谢。我还发现以这种格式保存 xlTextPrinter 也可以避免这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    相关资源
    最近更新 更多