Private Sub Form_Load()
Debug.Print TextFileLines("c:\autoexec.bat")
End Sub
Function TextFileLines(strFile As String)
Dim s As String
Dim b() As Byte
Dim fh As Long
fh = FreeFile
Open strFile For Binary As fh
ReDim b(LOF(fh))
Get fh, , b
Close #fh
If b(0) = 255 And b(1) = 254 Then '(Unicod 文本文件)
s = b
Else '(ANSI 文本文件)
s = StrConv(b, vbUnicode)
End If
TextFileLines = Len(s) - Len(Replace(s, vbCr, "")) + 1
End Function