vba 如何获得文本文件的总行数
需要将.txt或者.bat文件的内容写入到数组中,需要知道源文件的总行数,如何获得源文件的总行数 vba
[解决办法]
Public Sub main()
Dim fso, sFile
Dim linecount As Integer
linecount = 0
Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0
fso = CreateObject("Scripting.FileSystemObject")
sFile = fso.OpenTextFile("d:\1.txt", ForReading, TristateFalse)
Do While Not sFile.AtEndOfStream
linecount = linecount + 1
sFile.SkipLine()
Loop
sFile.Close()
fso = Nothing
sFile = Nothing
End Sub