0

I need to create a macro to write a .txt file and send it to our server, but our server only recognizes a new line, if there is an "enter" (chr 10) character at the end of the line. But everytime i write chr(10) at the end of the line, it creates a new line and macro writes at the next line of it like

Example (enter character sent here)
<---- new line
Next content

But server wont recognize the next content if the line before it is empty it must be like

Example (enter character sent here)
Next content

So far i have this to write the .txt file

Private Sub E16_Click()
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim f As Object
Dim order
pedido = Sheets("EDI").Range("I2")
Set f = fs.OpenTextFile("c:\" & IIf(Range("AA24") = 2, "temp\", "") & "pc" & order & ".txt", 2, True)

f.writeline "ITP" & Sheets("EDI").Range("C2") & Sheets("EDI").Range("J2") & Sheets("EDI").Range("L2") & WorksheetFunction.Rept(" ", 75) ' **Enter character must be sent here**
f.writeline Sheets("EDI").Range("M2") ' **Enter character must be sent here**
f.writeline "AE3" & Sheets("EDI").Range("J2") & "04771370000183" & Sheets("EDI").Range("J2") & WorksheetFunction.Rept(" ", 83) ' **Enter character must be sent here**

Is there anyway to send an enter character without creating a new line? I tried to format the Enter character as a text and didnt work

Mikku
  • 6,538
  • 3
  • 15
  • 38
Sirius_Black
  • 471
  • 3
  • 11
  • [This what you're looking for?](https://stackoverflow.com/questions/27223228/differences-between-vblf-vbcrlf-vbcr-constants) – Tom Aug 19 '19 at 14:35
  • No, that will do the same as chr(10) or chr(13) or chr(10)+chr(13) i need to send Enter character as a text and do not create a new line, i tried to use that and didnt work – Sirius_Black Aug 19 '19 at 14:39

1 Answers1

2

I think your issue is that you are using f.writeline instead of f.write

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/write-method

Alan Cheung
  • 244
  • 1
  • 7