VB读取一个文件夹里的TXT文件

2024-11-25 05:35:37
推荐回答(2个)
回答1:

添加引用 Microsoft Scripting Runtime

Dim fso As New FileSystemObject
Dim fts As TextStream
Dim fp As String
Dim rst As String

fp = "c:\a.txt"
Set fts = fso.OpenTextFile(fp, ForReading, False, TristateUseDefault)
rst = fts.ReadAll
set fts=Nothing
set fso=Nothing
MsgBox rst

回答2:

Function ReadTXT(TXTFile As String) As String
Dim FD() As Byte
Open TXTFile For Binary As #1
ReDim FD(1 To LOF(1)) As Byte
Get #1, , FD
Close #1
ReadTXT = StrConv(FD, vbUnicode): Erase FD
End Function