I have a text file and this is part of the text in the text file
Code: Select all
:↵:
Code: Select all
CreateObject("Scripting.FileSystemObject").OpenTextFile(ThisWorkbook.Path & "\FormData.txt").ReadAll
How can I read it correctly ??
Code: Select all
:↵:
Code: Select all
CreateObject("Scripting.FileSystemObject").OpenTextFile(ThisWorkbook.Path & "\FormData.txt").ReadAll
Code: Select all
Sub Test()
Dim stm As Object
Dim lin As String
Dim pos As Long
Dim c As String
Set stm = CreateObject("ADODB.Stream")
With stm
.Open
.Type = 2 ' adTypeText
.Charset = "UTF-8"
.LoadFromFile ThisWorkbook.Path & "\FormData.txt"
lin = .ReadText
.Close
pos = InStr(lin, ":")
c = Mid(lin, pos + 1, 1)
Debug.Print AscW(c)
End With
End Sub
Code: Select all
Sub ImportViaVBAOpenForAsWay()
' 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 & "\" & "FormDataShortened.txt" '
Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundemental type data input...
TotalFile = Space(LOF(FileNum)) '....and wot recives it has to be a string of exactly the right length
Get #FileNum, , TotalFile
Close #FileNum
' see whats in it
Dim Pos As Long, strC As String
Let Pos = InStr(TotalFile, ":")
Let strC = Mid(TotalFile, Pos + 1, 1)
Debug.Print AscW(strC)
End Sub