Hi
The macro seems to work OK using this version of the macro below and your uploaded files
Here is the output Share ‘Alert..txt’ : https://app.box.com/s/vyco4q3kgo8isalq48f926ftroyptri2
Code:
Sub xlsxTotxt_LineSeperatorvbLf_valuesSeperatorComma()
Rem 1 Workbooks info
Dim Wb1 As Workbook ': Set Wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\Alert..xls")
Set Wb1 = Workbooks("Alert..xls")
Dim Ws1 As Worksheet: Set Ws1 = Wb1.Worksheets.Item(1)
Dim Lr As Long, Lc As Long
Let Lr = Ws1.Cells.Range("A" & Ws1.Rows.Count & "").End(xlUp).Row
Let Lc = Ws1.Cells.Item(1, Ws1.Columns.Count).End(xlToLeft).Column
Dim arrIn() As Variant: Let arrIn() = Ws1.Range(Ws1.Range("A1"), Ws1.Cells.Item(Lr, Lc)).Value ' Data range in sample2.xlsx
Rem 2 make text file long string
Dim Rw As Long, Clm As Long '
For Rw = 1 To Lr ' each row in Ws1
For Clm = 1 To Lc ' each column for each row in Ws1
Dim strTotalFile As String
Let strTotalFile = strTotalFile & arrIn(Rw, Clm) & "," ' add a value and a seperator for this line
Next Clm
Let strTotalFile = Left(strTotalFile, Len(strTotalFile) - 1) ' this will take off the last ,
Let strTotalFile = strTotalFile & vbLf ' this adds the line seperator wanted by Avinash - https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)/page30#post13348 - You will see that vbLf is the separator for lines(records)
Next Rw
Let strTotalFile = Left(strTotalFile, Len(strTotalFile) - 1) ' this takes off the last vbLf
Debug.Print strTotalFile
Rem 3 make text file from the total string
Dim FileNum As Long
Let FileNum = FreeFile(1) ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
Open ThisWorkbook.Path & "\Alert..txt" For Output As #FileNum
' Open ThisWorkbook.Path & "C:\Users\WolfieeeStyle\Desktop\Alert..txt" For Output As #FileNum ' CHANGE TO SUIT ' Will be made if not there
Print #FileNum, strTotalFile ' strTotalFile
Close #FileNum
End Sub
Possibly your error was this
Code:
Open ThisWorkbook.Path & "C:\Users\WolfieeeStyle\Desktop\Alert..txt" For Output As #FileNum ' CHANGE TO SUIT ' Will be made if not there
You probably meant to write this:
Code:
Open "C:\Users\WolfieeeStyle\Desktop\Alert..txt" For Output As #FileNum ' CHANGE TO SUIT ' Will be made if not there
Or this
Code:
Open ThisWorkbook.Path & "\Alert..txt" For Output As #FileNum ' CHANGE TO SUIT ' Will be made if not there
Alan
P.S.
Just to check that you understand what is ThisWorkbook.Path, run this
Code:
Sub WhatIsThisWorkbook_Path()
MsgBox Prompt:=ThisWorkbook.Path
End Sub
Bookmarks