我尝试了这两种方法。一个工作得很好,而另一个却不行。有人能解释一下原因吗?
1-这个成功了
Dim scount As Integer
Dim x As Integer
scount = WordDoc.Shapes.Count
For x = 1 To scount
WordDoc.Shapes(x).Select
If WordDoc.Shapes(x).TextFrame.HasText = True Then
With WordDoc.Shapes(x).TextFrame.TextRange.Find
.Text = "World"
.Replacement.Text = "505"
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End If
Next x2-这个不起作用
Dim Shp As Shape
For Each Shp In ActiveDocument.Shapes
Shp.Select
With Selection.Find
.Text = "World"
.Replacement.Text = "Here"
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next发布于 2020-05-12 14:35:23
您的第二个宏不起作用,因为它没有解决TextFrame或TextRange问题。这将会起作用:
Dim Shp As Shape
For Each Shp In ActiveDocument.Shapes
With Shp
If .TextFrame.HasText = True Then
With .TextFrame.TextRange.Find
.Text = "World"
.Replacement.Text = "Here"
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
End If
End With
Nexthttps://stackoverflow.com/questions/61745041
复制相似问题