'------------------------------------------------------
'过程功能:查找文本框中字符串
'objTextBox 要搜索的文本所在的文本框控件
'strSearch 要搜索的字符串
'------------------------------------------------------
Sub sFindStr(objTextBox As TextBox, strSearch As String)
Dim intWhere As Integer
With objTextBox
'指定一字符串在另一字符串中最先出现的位置
intWhere = InStr(.Value, strSearch)
If intWhere Then
'查找
.SetFocus
.SelStart = intWhere - 1
.SelLength = Len(strSearch)
Else
'如未有指定字符,提示.
MsgBox "未找到你所查找的字符串!", vbOKOnly + vbInformation, "系统提示:"
End If
End With
End Sub
演示实例下载:点击下载此附件