问题描述:

So, I have this piece of code which do exactly what I want: append a new line into a text file using the contents of the cell A1. But when I look at the file, The lines have that "new line" character. How can I avoid my code to write that character?

That's my code.

Sub append_data()

Dim srtfile_path As String

strfile_path = "C:\Users\me\textfile.txt"

output = StrConv(Worksheets("Sheet1").Range("A1"), vbUnicode)

linebreak = StrConv(vbNewLine, vbUnicode)

Open strfile_path For Append As #1

Print #1, output + linebreak

Close #1

End Sub

网友答案:

If you wish to not only delete the linebreak that you are explicitly writing, but also the linebreak that separates one line from the next in a text file, you need to place a semi-colon (;) at the end of the Print statement:

Sub append_data()
    Dim srtfile_path As String
    strfile_path = "C:\Users\me\textfile.txt"
    output = StrConv(Worksheets("Sheet1").Range("A1"), vbUnicode)
    Open strfile_path For Append As #1
    Print #1, output;
    Close #1
End Sub
相关阅读:
Top