在 Powerpoint 中使用 InputBox 替换

Replace using InputBox in Powerpoint

我想使用用户的输入替换所有幻灯片中的“仪器”一词。 下面的代码在我设置 Replacement = "ppp" 时有效,但是当我将其更改为 Replacement = InputBox 时,仪器不会被用户输入替换。

有什么建议吗?

Sub Replaceinstrument()
    Dim sld As Slide
    Dim shp As Shape
    Dim Replacement As String
    

    For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes

    
    Replacement = InputBox("to change")
    
    If Replacement = "" Then Exit Sub
    
               
    If shp.HasTextFrame Then
        If shp.TextFrame.HasText Then
             With shp.TextFrame.TextRange
              .Replace "instrument", Replacement
                    
             End With
                             
            End If
        End If
        
    Next shp
    
Next

End Sub

因为循环中有 InputBox,所以演示文稿中的每个形状都是 运行。这是工作顺序:

Sub Replaceinstrument()
    Dim sld As Slide
    Dim shp As Shape
    Dim Replacement As String

    Replacement = InputBox("to change")
    If Replacement = "" Then Exit Sub
    
    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
            If shp.HasTextFrame Then
                If shp.TextFrame.HasText Then
                    shp.TextFrame.TextRange.Replace "instrument", Replacement
                End If
            End If
        Next shp
    Next
End Sub