Private Function FileText(ByVal filename As String) As String
Dim handle As Integer
' 判断文件存在性
On Error GoTo err
If Len(Dir$(filename)) = 0 Then
err.Raise 53 '文件没有找到
End If
' 以binary模式打开文件
handle = FreeFile
Open filename$ For Binary As #handle
'读取内容,关闭文件
FileText = Space$(LOF(handle))
Get #handle, , FileText
Close #handle
Exit Function
err:
Exit Function
End Function
Private Sub Command1_Click()
Dim filenum As Integer
Dim fileContents As String
Dim fileInfo() As String
Dim i As Integer
filenum = FreeFile
Open "c:\1.txt" For Binary As #filenum
fileContents = Space(LOF(filenum))
Get #filenum, , fileContents
Close filenum
fileInfo = Split(fileContents, vbCrLf)
For i = 0 To UBound(fileInfo) - 1
Debug.Print fileInfo(i)
Next
Close #filenum
End Sub