【问题标题】:Replace using InputBox in Powerpoint在 Powerpoint 中使用 InputBox 替换
【发布时间】:2020-11-07 09:36:10
【问题描述】:

我想使用来自用户的输入替换所有幻灯片中的“仪器”一词。 下面的代码在我设置 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

【问题讨论】:

    标签: vba powerpoint inputbox


    【解决方案1】:

    因为循环中有 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
    

    【讨论】:

    • 我错过了这么简单的事情。谢谢!
    猜你喜欢
    • 2023-03-30
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多