【问题标题】:Replace TextBox in MS-Word替换 MS-Word 中的文本框
【发布时间】:2020-08-27 21:35:17
【问题描述】:

我尝试了这两种方法。一个工作正常,但另一个没有。有人解释原因吗?

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 x

2- 这个没用

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

【问题讨论】:

    标签: vba replace ms-word textbox


    【解决方案1】:

    您的第二个宏不起作用,因为它没有解决 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
    Next
    

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      相关资源
      最近更新 更多