open filename for input as #1 i=0 do until eof(1) line input #1,str1 i=i+1 loopi即为文本文件的行数
superzhou(学海无涯),其实我也是这么做的, 还有什么好办法吗?
Dim TempFile As Long Dim LoadBytes() As ByteTempFile=FreeFile Open 文件名 For Binary As #TempFile Redim LoadBytes(1 To Lof(TempFile)) As Byte Get #TempFile,,LoadBytes Close TempFile行数=UBound(Split(StrConv(LoadBytes,vbUniCode),vbCrLf))+1
如果行太多(上万),效率都很低! 建议: 引用 Microsoft Scripting Runtime !(FSO) Dim xx As New Scripting.FileSystemObject Dim yy As Scripting.TextStream Set yy = xx.OpenTextFile("d:\test.txt") yy.ReadAll VBA.MsgBox yy.Line
i=0
do until eof(1)
line input #1,str1
i=i+1
loopi即为文本文件的行数
还有什么好办法吗?
Dim LoadBytes() As ByteTempFile=FreeFile
Open 文件名 For Binary As #TempFile
Redim LoadBytes(1 To Lof(TempFile)) As Byte
Get #TempFile,,LoadBytes
Close TempFile行数=UBound(Split(StrConv(LoadBytes,vbUniCode),vbCrLf))+1
建议:
引用 Microsoft Scripting Runtime !(FSO)
Dim xx As New Scripting.FileSystemObject
Dim yy As Scripting.TextStream
Set yy = xx.OpenTextFile("d:\test.txt")
yy.ReadAll
VBA.MsgBox yy.Line