VBA not reading all of the text file into array

BalloutMoe

Board Regular
Joined
Jun 4, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hello All
I have the below code just a sample that reads a TextFile so I can loop it however it is not reading the whole file. When I open the text file and save it as a UTF8 with no BOM from the ANSI format it read it all, any help with this? How can I read it as the ANSI format. Thank you
VBA Code:
 Dim fso As Object
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fileopening = fso.OpenTextFile(txtFileName, 1)
   arrTxt = Split(fileopening.ReadAll, vbNewLine) 'vbCrLf
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Does this work with your file (change PathAndFileName to your actual path and filename)...
VBA Code:
  Dim FileNum As Long, TotalFile As String, ArrTxt As Variant
  FileNum = FreeFile
  Open PathAndFileName For Binary As #FileNum
    TotalFile = Space(LOF(FileNum))
    Get #FileNum, , TotalFile
  Close #FileNum
  ArrTxt = Split(TotalFile, vbNewLine)
 
Upvote 0
Solution
Does this work with your file (change PathAndFileName to your actual path and filename)...
VBA Code:
  Dim FileNum As Long, TotalFile As String, ArrTxt As Variant
  FileNum = FreeFile
  Open PathAndFileName For Binary As #FileNum
    TotalFile = Space(LOF(FileNum))
    Get #FileNum, , TotalFile
  Close #FileNum
  ArrTxt = Split(TotalFile, vbNewLine)
I literally came across this on the web after posting the thread and it worked. I appreciate your reply either way. Thank you
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top