返回列表 上一主題 發帖

[發問] 如何得知搜尋結果的數量?

[發問] 如何得知搜尋結果的數量?

objSelection.WholeStory
                objSelection.Find.ClearFormatting
                objSelection.Find.Text = tt
                objSelection.Find.Replacement.Text = ""
                objSelection.Find.Forward = True
                objSelection.Find.Wrap = wdFindContinue
                objSelection.Find.Format = False
                objSelection.Find.MatchCase = False
                objSelection.Find.MatchWholeWord = False
                objSelection.Find.MatchByte = True
                objSelection.Find.CorrectHangulEndings = False
                objSelection.Find.MatchAllWordForms = False
                objSelection.Find.MatchSoundsLike = False
                objSelection.Find.MatchWildcards = False
                objSelection.Find.MatchFuzzy = False
                objSelection.Find.Execute
                objSelection.TypeText Text:=CStr(rr)
                objSelection.Find.Execute , , , , , , , , , , wdReplaceAll


以上之程式碼可以完成我搜尋的工作,並且取代成功
但要如何得知有"幾個"搜尋結果,將搜尋結果的數量變成一個變數名稱ex:findN
而我就可以執行其他動作
if findN =0 then XXXXX

麻煩各位大大了
PKKO

提問一下,這個是不是可以用迴圈來統計搜尋結果的數量?
學習VBA

TOP

回復 2# s90068
如何使用?
沒有看到有顯示數量的地方
不知道怎樣跑迴圈
PKKO

TOP

回復 3# PKKO

這個是WORD說明功能中的例子:

Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="blue", Forward:=True
If myRange.Find.Found = True Then myRange.Bold = True

,想說用 Find.Found 搭判斷式及迴圈 看是否行得通
學習VBA

TOP

我自己的例子,請自行研究!

    總字數 = 0
    造字統計字串 = ""
    For X = 0 To UBound(完整的造字陣列)
        With Selection.Find
            .ClearFormatting
            .Text = 完整的造字陣列(X)
            .Forward = False
            .Wrap = wdFindStop
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchByte = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            
            各別字數 = 0
            Do
                .Execute 'Forward:=True
               
                If .Found = True And Selection.Range.InRange(造字統計範圍) Then
                    各別字數 = 各別字數 + 1
                    總字數 = 總字數 + 1
                Else
                    If 各別字數 > 0 Then
                        造字統計字串 = 造字統計字串 & 完整的造字陣列(X) & "-" & 各別字數 & "_"
                    End If
                    
                    Exit Do
                End If
            Loop
        End With
        
        造字統計範圍.Select
    Next X

TOP

回復 5# linyancheng


    感恩
PKKO

TOP

        靜思自在 : 道德是提昇自我的明燈,不該是呵斥別人的鞭子。
返回列表 上一主題