我正在使用下面的代码。它不是将数据逐行放入单元格中,而是将所有数据放入一个单元格中。附上图片供您参考。还附上了我正在阅读的示例文本文件。请注意,当我尝试在写字板中打开此文本文件并保存它时,它可以正常工作。
Sub Test_ReadFromTxtToArray()
Dim FSO As Object, MyFile As Object
Dim FileName As String, Arr As Variant
FileName = "C:\Test\O0000540.txt" ' change this to your text file full name
Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFile = FSO.OpenTextFile(FileName, 1)
Arr = Split(MyFile.ReadAll, vbCrLf) ' Arr is zero-based array
'For test
'Fill column A from this Array Arr
Sheet2.Range("A1").Resize(UBound(Arr) + 1, 1).Value = Application.Transpose(Arr)
End Sub