[Visual Basic] 纯文本查看 复制代码 Private Sub CommandButton1_Click()
Dim d
Dim i, sr$, temp
Dim filter As String
Dim fileToOpen
filter = "Text Files(*.*),* "
fileToOpen = Application.GetOpenFilename(filefilter:=filter, FilterIndex:=2, Title:="请选择文件")
Set d = CreateObject("scripting.dictionary") '引用字典
With Sheets("sheet1")
.UsedRange.ClearContents '清除原有的数据
i = 1
Open fileToOpen For Input As #1 '使用open语句输入
Do While Not EOF(1) '运行到文件的结尾结束
Line Input #1, sr '按行读取数据
ssr = ssr & sr
i = i + 1
If i = 50 Then Exit Do
Loop
Close #1 '关闭文本文件
i = 2
For j = 1 To Len(ssr)
If Mid(ssr, j, 1) = "(" Then
If i = 2 Then
d(1) = Mid(ssr, 1, j - 1)
End If
Dim aaa As String
aaa = Mid(ssr, j, InStr(j, ssr, ")") - j + 1)
d(i) = aaa '以_分割字符串
i = i + 1
End If
Next
For i = 1 To d.Count + 1
.Cells(1, i) = d(i)
Next
End With
Set d = Nothing
End Sub
|