Dec 2020-11-29
If I make text file with nothing in it and then after look at the text file with the following macro ..._
Code:
' A virgin text file
Sub AVirginTextFile()
' 1 Make a virgin text file
Dim FileNum2 As Long: Let FileNum2 = FreeFile(0) ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
Dim PathAndFileName2 As String
Let PathAndFileName2 = ThisWorkbook.Path & "\" & "NoText.txt" ' CHANGE path TO SUIT
Open PathAndFileName2 For Output As #FileNum2
Dim NoText As String
Print #FileNum2, NoText ' write out entire text file, the file is made if not there
Close #FileNum2
' 2a) Get the text file as a long single string
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 & Application.PathSeparator & "NoText.txt" ' CHANGE TO SUIT From vixer zyxw1234 : http://www.eileenslounge.com/viewtopic.php?f=30&t=34629 DF.txt https://app.box.com/s/gw941dh9v8sqhvzin3lo9rfc67fjsbic
Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundamental type data input...
Let TotalFile = Space(LOF(FileNum)) '....and wot receives it has to be a string of exactly the right length
Get #FileNum, , TotalFile 'Debug.Print TotalFile
Close #FileNum
Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(TotalFile)
End Sub
_... then I will see nothing at all in Notepad, and from my WotchaGot function it will tell me that I have
vbCr & vbLf
If I Let NoText = "x" , and repeat the experiment, I see in notepad .._
_.. and my function tells me that I have
"x" & vbCr & vbLf
Here are some more experiments, and the results:
Let NoText = "x" & vbCr & "x"
"x" & vbCr & "x" & vbCr & vbLf
Let NoText = "x" & vbLf & "x"
"x" & vbLf & "x" & vbCr & vbLf
Let NoText = "x" & vbCr & vbLf & "x"
"x" & vbCr & vbLf & "x" & vbCr & vbLf
Let NoText = "x" & vbLf & vbCr & "x"
"x" & vbLf & vbCr & "x" & vbCr & vbLf
If I repeat the experiment using extension .csv instead of .txt everywhere in my macro, then the results are identical.
So it appears that notepad only recognises the pair vbCr & vbLf as a new line
( Note: if I open any of the files ( .txt or .csv ) in Excel , using any default settings, then for the case of the vbLf or the vbCr or the pair vbCr & vbLf then Excel always seems to add a line and I see
_____ Workbook: NoText.txt ( Using Excel 2007 32 bit )
Worksheet: NoText
_____ Workbook: NoText.csv ( Using Excel 2007 32 bit )
Worksheet: NoText
For the case of using vbLf & vbCr, using the default settings opening in Excel the .txt file also gives the same result, but strangely for the .csv file we see an extra line
_____ Workbook: NoText.csv ( Using Excel 2007 32 bit )
Worksheet: NoText
Bookmarks