TextRange的findText方法如何向上查找这是MSDNhttp://msdn.microsoft.com/en-us/library/ms536422(VS.85).aspxbFound = TextRange.findText(sText [, iSearchScope] [, iFlags])意思是好象第二个参数 iSearchScope为正就向下 为负就向上可是我试了oRange.findText(nWord, 1)
是可以一直向下查找的可oRange.findText(nWord, -1) 就跳到最后一个字母去了A去了(比如一直查找)@a @ABBA @a a b A B如何让他循环查找?以下是代码'查找 单个
Public Sub FindWordOne(nWord$)
On Error GoTo due
If LenB(Trim$(nWord)) = 0 Then Exit Sub
Static tBookMark As String 'As Object
Static tPreWord$
Static tPreWb As SHDocVw.WebBrowser
Dim tWb As Object 'html window
Dim tWbs As CollectionDim HaveFind As Boolean
HaveFind = FalseSet tWbs = New Collection
tWbs.Add webMe
Call EnumFrames(webMe, tWbs)If nWord <> tPreWord Then
'Set tBookMark = Nothing
tBookMark = vbNullString
Set tPreWb = Nothing 'webMe
tPreWord = nWord
End IfFor Each tWb In tWbs
If tPreWb Is Nothing Then
Set tPreWb = tWb
End If
If tWb Is tPreWb Then
If FindWord2One(nWord, tWb.Document, tBookMark) Then
HaveFind = True
Exit For
Else
Set tPreWb = Nothing
End If
End If
Next tWbIf Not HaveFind Then
tBookMark = vbNullString
Set tPreWb = Nothing
tPreWord = vbNullString
MsgBox "文档搜索完毕", vbExclamation
End IfExit Subdue:
ErrorLog.AddLog "FindWord:" & Err.Description
End Sub
Private Function FindWord2One(nWord$, nDoc As MSHTML.HTMLDocument, nPosBM As String) As Boolean
Dim oRange As MSHTML.IHTMLTxtRange
Set oRange = nDoc.body.createTextRange
'If Not nPosBM Is Nothing Then
If LenB(nPosBM) > 0 Then
Call oRange.moveToBook(nPosBM)
Call oRange.moveStart("character", 1)
End If
If oRange.findText(nWord, -1) Then
nPosBM = oRange.getBook
'Call oRange.moveToBook(nPosBM)
Call oRange.Select
FindWord2One = True
Else
'Set nPosBM = Nothing
nPosBM = vbNullString
FindWord2One = False
End If
End Function
是可以一直向下查找的可oRange.findText(nWord, -1) 就跳到最后一个字母去了A去了(比如一直查找)@a @ABBA @a a b A B如何让他循环查找?以下是代码'查找 单个
Public Sub FindWordOne(nWord$)
On Error GoTo due
If LenB(Trim$(nWord)) = 0 Then Exit Sub
Static tBookMark As String 'As Object
Static tPreWord$
Static tPreWb As SHDocVw.WebBrowser
Dim tWb As Object 'html window
Dim tWbs As CollectionDim HaveFind As Boolean
HaveFind = FalseSet tWbs = New Collection
tWbs.Add webMe
Call EnumFrames(webMe, tWbs)If nWord <> tPreWord Then
'Set tBookMark = Nothing
tBookMark = vbNullString
Set tPreWb = Nothing 'webMe
tPreWord = nWord
End IfFor Each tWb In tWbs
If tPreWb Is Nothing Then
Set tPreWb = tWb
End If
If tWb Is tPreWb Then
If FindWord2One(nWord, tWb.Document, tBookMark) Then
HaveFind = True
Exit For
Else
Set tPreWb = Nothing
End If
End If
Next tWbIf Not HaveFind Then
tBookMark = vbNullString
Set tPreWb = Nothing
tPreWord = vbNullString
MsgBox "文档搜索完毕", vbExclamation
End IfExit Subdue:
ErrorLog.AddLog "FindWord:" & Err.Description
End Sub
Private Function FindWord2One(nWord$, nDoc As MSHTML.HTMLDocument, nPosBM As String) As Boolean
Dim oRange As MSHTML.IHTMLTxtRange
Set oRange = nDoc.body.createTextRange
'If Not nPosBM Is Nothing Then
If LenB(nPosBM) > 0 Then
Call oRange.moveToBook(nPosBM)
Call oRange.moveStart("character", 1)
End If
If oRange.findText(nWord, -1) Then
nPosBM = oRange.getBook
'Call oRange.moveToBook(nPosBM)
Call oRange.Select
FindWord2One = True
Else
'Set nPosBM = Nothing
nPosBM = vbNullString
FindWord2One = False
End If
End Function
在Range中查找sText
iSearchScope 开始位置,负数方向搜索
iFlags 2(整词匹配) 4(区别大小写)