1

I am developing process that

copy text file and edit text file content according to Excel data by using FileSystemObject.

Although Line Break Code of original text file is [0A(VBLF)],

after editing, Line Break Code of updated text file becomes [0D 0A(VBCRLF)].

I would like to write Line Break Code as original text file.

What is the best way of doing this? Thanks in advance.

1 Answer 1

1

If you write your text file line by line, you can choose your line break

Sub sampleWriteVBLF()

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFile = fso.CreateTextFile("D:\test.txt", True)

    objFile.Write "Hello" & vbLf
    objFile.Write "World" & vbLf

    objFile.Close

End Sub

enter image description here

            VBA       VBA               HEX     NAME
LF    \n    VbLf      Chr(10)           0x0A    Line Feed
CR    \r    VbCr      Chr(13)           0x0D    Carriage Return
CR+LF \r\n  VbCrLf    Chr(10)&Chr(13)   0x0D0A  Carriage Return Line Feed    

Edit: You must use .write because .WriteLine will always append an additional CRLF linebreak. But you already have a LF line break

5
  • Thanks for reply. But I have tested that way. After writing as that way, Line Break Code of updated text file becomes [0A 0D 0A]. I want only [0A]. Please explain me.
    – user275763
    Dec 5, 2013 at 7:16
  • @user275763 What operating system and editor for viewing the line break are you using?
    – nixda
    Dec 5, 2013 at 8:09
  • I am using Operating System: Window7 editor for viewing the line break: Stirling
    – user275763
    Dec 5, 2013 at 8:23
  • 1
    @user275763 Are you using .Writeline instead of .Write? That would explain why you get LF+CRLF (or in HEX 0A 0D 0A)
    – nixda
    Dec 5, 2013 at 17:45
  • Thank you very much. I got only Line Break Code [OA] after using .Write. >>Are you using .Writeline instead of .Write? Yes.I was using .Writeline. Thanks a lot for explaining difference between of .Write and .Writeline.
    – user275763
    Dec 6, 2013 at 0:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .