open打开文件需要有个完全的路径名称,
建议先使用GetOpenFilename获取需要打开的文件全名称.
再使用open进行文件流操作.
dim count as long
Dim Filt As String
Dim FilterIndex As Integer
Dim Title As String
Dim File As Variant
Dim fText As String
'创建文件筛选列表
Filt = "Text Files (*.txt),*.txt,"
'默认显示*.*
FilterIndex = 1
'设置对话框标题
Title = "打开文本文件"
'获取文件路径以及文件名
File = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
'如果取消对话框则退出
If File = False Then
MsgBox "您未选择文件"
Exit Sub
End If
'excel获取文本数据
Open File For Input As #1
count = 0
Do While Not EOF(1)
count = count + 1
Line Input #1, fText
Worksheets("Sheet1").Cells(count, 1).Value = fText
Loop
Close #1
温馨提示:答案为网友推荐,仅供参考