共用方式為


Application.ReplaceFormat 屬性 (Excel)

設定取代準則用以取代儲存格格式。 然後,取代準則會在 Range 物件的 Replace 方法的後續呼叫中使用。

語法

表達。取代格式

expression 代表 Application 物件的變數。

範例

下列範例會設定搜尋準則,以尋找包含 Arial、Regular、Size 10 字型的儲存格,將其格式取代為 Arial、Bold、Size 8 字型,然後呼叫 Replace 方法,並將 SearchFormatReplaceFormat 的選擇性引數設定為 True 以實際進行變更。

Sub MakeBold() 
 
 ' Establish search criteria. 
 With Application.FindFormat.Font 
 .Name = "Arial" 
 .FontStyle = "Regular" 
 .Size = 10 
 End With 
 
 ' Establish replacement criteria. 
 With Application.ReplaceFormat.Font 
 .Name = "Arial" 
 .FontStyle = "Bold" 
 .Size = 8 
 End With 
 
 ' Notify user. 
 With Application.ReplaceFormat.Font 
 MsgBox .Name & "-" & .FontStyle & "-" & .Size & _ 
 " font is what the search criteria will replace cell formats with." 
 End With 
 
 ' Make the replacements on the worksheet. 
 Cells.Replace What:="", Replacement:="", _ 
 SearchFormat:=True, ReplaceFormat:=True 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應