返回列表 上一主題 發帖

[發問] 用Excel開啟word後的搜尋問題

本帖最後由 luhpro 於 2014-12-21 23:15 編輯
以上之程式碼可以完成我搜尋的工作,並且取代成功
但要如何得知有"幾個"搜尋結果,將搜尋結果的數量變成一個 ...
PKKO 發表於 2014-12-19 10:35

一般有同一物件多次引用時可以用 With ... End With 包起來,
其中再以 . 取代此物件:
你的程式可以改為 :
  1. With objSelection
  2.   .WholeStory
  3.   With .Find
  4.     .ClearFormatting
  5.     .Text = tt
  6.     .Replacement.Text = ""
  7.     .Forward = True
  8.     .Wrap = wdFindContinue
  9.     .Format = False
  10.     .MatchCase = False
  11.     .MatchWholeWord = False
  12.     .MatchByte = True
  13.     .CorrectHangulEndings = False
  14.     .MatchAllWordForms = False
  15.     .MatchSoundsLike = False
  16.     .MatchWildcards = False
  17.     .MatchFuzzy = False
  18.     .Execute
  19.   End With
  20.   .TypeText Text:=CStr(rr)
  21.   .Find.Execute , , , , , , , , , , wdReplaceAll
  22. End With
複製代碼
另取得被取代文字數量的方式我沒找到,
但你的需求可以用下式來實現:
if Not objSelection.Find then XXXXX

TOP

        靜思自在 : 生氣,就是拿別人的過錯來懲罰自己。
返回列表 上一主題