将字符串添加到shape对象的行尾

时间:2017-03-19 07:32:28

标签: vba word-vba

我在形状对象特定的字符串中搜索,并在更改后用另一个字符串替换,我想再添加一行字符串。

我使用的第一部分(搜索字符串和替换):

set oShape = ActiveDocument.Shapes(indexShape).TextFrame.TextRange
With oShape.find
    .ClearFormatting
    .Text = i_wordToFind
    .Replacement.ClearFormatting
    .Replacement.Text = i_ValueResponsible
    .MatchWholeWord = True
    .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindStop
End With

如何将字符串添加到我找到字符串的行尾?

感谢, 塔尔

1 个答案:

答案 0 :(得分:0)

虽然它仅在第一次出现时取代i_WordToFind,但这应该可以帮到你。

Private Sub InputTal()

    Dim oShape As Shape
    Dim Rng As Range

    Set oShape = ActiveDocument.Shapes(indexShape)
    Set Rng = oShape.TextFrame.TextRange
    Rng.Find.Execute FindText:=i_WordToFind, Forward:=True
    If Rng.Find.Found Then
        With Rng
            .Text = i_ValueResponsible
            .MoveUntil Cset:=Chr(11) & Chr(13)
            .Text = " " & i_ValueResponsible
        End With
    End If
End Sub