My excel file has 3 sheets, one that contains a mass amount of static data (we'll call this Build Status), one that accepts data input (we'll call this Input) and one that returns data from Build Status sheet using IF and VLOOKUP functions based on values from Input sheet (we'll call this sheet Output). My Output sheet has static headers and my macro creates a csv from the Output sheet (macro tied to a button). For some reason I end up with a carriage return at the end of my .txt file (csv saved as .txt) and I have to delete it in order for the HMI of another program to accept the upload format. Any help on getting rid of the return or why it's being created would be appreciated.
Whether outputting as .csv or .txt (in csv format), the carriage return is there when viewing in a text editor.
Option Explicit
Sub CreateCSV()
Dim wbI As Workbook, wbO As Workbook
Dim wsI As Worksheet, wsO As Worksheet
Dim jLastRow As Long
Dim LDate As String
'~~> Set a format for current date
LDate = Format(Date, "mm-dd-yyyy")
'~~> Source/Input Workbook
Set wbI = ThisWorkbook
'~~> Set the relevant sheet from where you want to copy
Set wsI = wbI.Sheets("OUTPUT")
'~~> Sets an integer value for the last row of data being copied
jLastRow = wsI.Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'~~> Destination/Output Workbook
Set wbO = Workbooks.Add
With wbO
'~~> Set the relevant sheet to paste to
Set wsO = wbO.Sheets("Sheet1")
'~~> Copy the range
wsI.Range("A1:Z" & jLastRow).Copy
'~~> Paste it in Cell A1.
wsO.Range("A1").PasteSpecial Paste:=xlPasteValues
'~~>. Save the file
.SaveAs Filename:="\\TestFolder\TestRecipe" & LDate & ".txt", FileFormat:=xlCSV
'~~> Clear Clipboard
Application.CutCopyMode = False
End With
End Sub
Expected: Creates comma separated values in .txt file named TestRecipe(Date) that works with third party software.
Actual: File creation, name and format work but a carriage return is at the end of the file which prevents it from uploading into third party software. As soon as I delete this manually, it uploads fine.