vba powerpoint:如何更改powerpoint中表格单元格中的选定文本?

问题描述 投票:0回答:1

我在powerpoint的表格单元格中选择了文本,如下图所示table in powerpoint

当我运行如下的vba sub时

Sub changeSelectedText()
    Set ppapp = GetObject(, "Powerpoint.application")
    Set pppres = ppapp.ActivePresentation
    Dim text As String
    text = "cell content change"
    selectionType = ppapp.ActiveWindow.Selection.Type
    ppapp.ActiveWindow.Selection.TextRange.text = text


End Sub

该行发生错误:ppapp.ActiveWindow.Selection.TextRange.text = text

所以我无法更改powerpoint的表格单元格中的选定文本。

vba powerpoint
1个回答
1
投票

如果您的代码将在PowerPoint本身内运行,则可以:

Sub changeSelectedText()

    Dim text As String
    text = "cell content change"
    ActiveWindow.Selection.TextRange.text = text

End Sub

如果您正在从其他应用程序驾驶PPT,请尝试使用此作为初学者。 Aircode。未经测试。警告计算器:

Sub changeSelectedText()
    Dim ppapp as object
    Dim pppres as Object
    Set ppapp = GetObject(, "Powerpoint.application")
    Set pppres = ppapp.ActivePresentation
    Dim text As String
    text = "cell content change"
    ' You haven't declared selectionType and don't
    ' use it for anything, so I've commented it out
    ' selectionType = ppapp.ActiveWindow.Selection.Type
    ppapp.ActiveWindow.Selection.TextRange.text = text

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.