BalloutMoe
Board Regular
- Joined
- Jun 4, 2021
- Messages
- 137
- Office Version
- 365
- Platform
- Windows
Hello all,
I am trying to read a large text file and put some of it in a new text file as a UTF-8 it keeps saving it as ANSI format any help on how to incorporate this in my code? Thank you
I am trying to read a large text file and put some of it in a new text file as a UTF-8 it keeps saving it as ANSI format any help on how to incorporate this in my code? Thank you
VBA Code:
Sub GetTextFile()
Const ForReading = 1, ForWriting = 2
Dim fso, FileIn, FileOut As Object, ArrFileTxt As Variant
Dim OGFileName As String, NewFileName As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set FileIn = fso.OpenTextFile("F:\Abe Files\My Downloads\Codes\UNIRECEIPTS.TXT", ForReading)
ArrFileTxt = Split(FileIn.ReadAll, vbCrLf)
For i = 50000 To UBound(ArrFileTxt)
If InStr(ArrFileTxt(i), "/2022") Then
Debug.Print "True"
i = i - 15
j = i
FileIn.Close
'Kill ("F:\Abe Files\My Downloads\Codes\BONHAMRECEIPTS - Copy.TXT")
Set FileOut = fso.CreateTextFile("F:\Abe Files\My Downloads\Codes\UNIRECEIPTSNEW.TXT")
GoTo WriteToFile
End If
Next
WriteToFile:
For t = j To UBound(ArrFileTxt)
FileOut.WriteLine Trim(ArrFileTxt(t)) & vbCrLf
Next
Set ArrFileTxt = Nothing
FileOut.Close
End Sub