'cmdChose為按鈕
'text1為文本框,此查詢區分大小寫
Private Sub cmdChose_Click()
With dlgCommonDialog
.DialogTitle = "打開到XML文件:"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有格式(*.*)|*.*"
.InitDir = App.Path
.FileName = ""
.ShowOpen
' .DefaultExt
If Len(.FileName) = 0 Then
Exit Sub
End If
TxtFilePath.Text = .FileName
Dim aline As String
Open .FileName For Binary As #1
aline = String((LOF(1)), Chr(0))
Get #1, , aline
Close #1
'註意查找時區分大小寫
If InStr(aline, Text1.Text) > 0 Then
'說明包含
MsgBox "找到該字符串"
Dim cmdstr As String
'如果用richtext打開該文件,可以定位位置
cmdstr = "notepad.exe " & .FileName
Shell cmdstr
Else
MsgBox "未找到該字符串"
End If
End With
End Sub