https://excelfox.com/forum/showthrea...sx-to-txt-file
https://excelfox.com/forum/showthrea...ll=1#post13318
http://www.eileenslounge.com/viewtopic.php?f=30&t=34610
http://www.eileenslounge.com/viewtop...267706#p267706
Alert..txt from Avinash : FromAvinashTextFileAlet__txt.JPG : https://imgur.com/HDHgB0z
Code:USA,101010,6,<,12783,A,,,,,GTT, USA,22,6,<,12783,A,,,,,GTT, USA,17388,6,<,12783,A,,,,,GTT, USA,100,6,<,12783,A,,,,,GTT, USA,25,6,<,12783,A,,,,,GTT,Code:"USA" & "," & "101010" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "22" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "17388" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "100" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "25" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLfYou will see that vbLf is the separator for lines(records)Code:"USA" & "," & "101010" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "22" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "17388" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "100" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf & "USA" & "," & "25" & "," & "6" & "," & Chr(60) & "," & "12783" & "," & "A" & "," & "," & "," & "," & "," & "GTT" & "," & vbLf
This is the macro i used to get that infomation:
Code:Sub WhatStringIsInAlertDotDot_txt() ' 9th June 2020 https://excelfox.com/forum/showthread.php/2518-convert-the-data-from-xlsx-to-txt-file Dim FileNum As Long: Let FileNum = FreeFile(1) ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function Dim PathAndFileName As String, TotalFile As String Let PathAndFileName = ThisWorkbook.Path & "\csv Text file Chaos\Alert..txt" ' This would be made if not existing and we would have a zero lenf string Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundemental type data input... Dim Lenf As Long: Let Lenf = LOF(FileNum) TotalFile = Space(Lenf) '....and wot recives it hs to be a string of exactly the right length Get #FileNum, , TotalFile Close #FileNum ' What the fuck is in this string? Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(TotalFile) ' 'https://excelfox.com/forum/showthread.php/2345-Appendix-Thread-(-Codes-for-other-Threads-HTML-Tables-etc-)/page34#post13699 https://excelfox.com/forum/showthread.php/2302-quot-What%E2%80%99s-in-a-String-quot-VBA-break-down-Loop-through-character-contents-of-a-string?p=11015&viewfull=1#post11015 End Sub
Here is the macro to answer this thread
https://excelfox.com/forum/showthrea...sx-to-txt-file
Code:' https://excelfox.com/forum/showthread.php/2518-convert-the-data-from-xlsx-to-txt-file Sub xlsxTotxt_LineSeperatorvbLf_valuesSeperatorComma() Rem 1 Workbooks info Dim Wb1 As Workbook: Set Wb1 = Workbooks("sample2.xlsx") 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 & "\csv Text file Chaos\Alert..txt" For Output As #FileNum ' CHANGE TO SUIT ' Will be made if not there Print #FileNum, strTotalFile ' strTotalFile Close #FileNum End Sub




Reply With Quote
Bookmarks