有条件的基础上是否replace发生

我想知道是否发生replace。 我想要做的是:

bool SomethingWasReplaced = ActiveWorkbook.Worksheets(i).Cells.Replace What:="foo", Replacement:="bar", _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False If SomethingWasReplaced Then ... 

我的互联网search没有透露一种方法来做到这一点。 我怎样才能达到我想要的?

我不认为有一种方法可以替代(尽pipe它在这里说的),你可能必须做一个search,然后replace

 Sub Test() Dim ws As Worksheet Dim search As Range Dim found As Range For Each ws In ThisWorkbook.Sheets Set search = ws.Cells Set found = search.Find(What:="foo", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False) Do While Not found Is Nothing found.replace What:="foo", replacement:="bar" '' you now know something was replaced here, do whatever else you need Set found = search.Find(What:="foo", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, After:=found) Loop Next ws End Sub 

我的怀疑是.Replace()返回true,如果它的工作(没有错误),而不是基于它是否实际取代任何东西。