PowerPoint) (TextRange.Find 方法
會指定的文字範圍中的文字,找出並傳回 TextRange 物件,代表找到之文字的第一個文字範圍。 會傳回 Nothing 如果找到不相符。
語法
運算式。尋找 (FindWhat、 After、 MatchCase、 WholeWords)
表達 代表 TextRange 物件的 變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
FindWhat | 必要 | String | 要搜尋的文字。 |
After | 選用 | Long | 要在其後開始搜尋下一個 FindWhat 的字元位置 (在指定的文字範圍中)。 例如,如果要從文字範圍的第五個字元開始搜尋,請指定 4 當做 After 的值。 如果省略此引數,就會以文字範圍的第一個字元做為搜尋的起始點。 |
MatchCase | 選用 | MsoTriState | msoTrue 會使搜尋能夠區分大小寫的字元。 |
WholeWords | 選用 | MsoTriState | msoTrue 會使搜尋能夠只會尋找整個字而不的較大字組件。 |
傳回值
TextRange
範例
本範例在目前的簡報中尋找有 "CompanyX" 文字出現的地方,並將其格式設定為粗體。
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
Set txtRng = shp.TextFrame.TextRange
Set foundText = txtRng.Find(FindWhat:="CompanyX")
Do While Not (foundText Is Nothing)
With foundText
.Font.Bold = True
Set foundText = _
txtRng.Find(FindWhat:="CompanyX", _
After:=.Start + .Length - 1)
End With
Loop
End If
Next
Next
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。