VBA Power Point:如何更改Powerpoint表单元格中的选定文本?

时间:2018-09-17 07:29:29

标签: vba powerpoint

我已经在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的表格单元中更改所选文本。

1 个答案:

答案 0 :(得分:1)

如果您的代码将在PowerPoint本身中运行,那么它将起作用:

%%writefile testcipher.py

import argparse
def parse_command_line():
    parser=argparse.ArgumentParser()
    parser.add_argument("infile",type=str,help="show this help message and exit")
    args=parser.parse_args()
    return args

def read_file(file_name):
    __file = open(file_name)
    message=__file.read()
    return message

args = parse_command_line()
message = read_file(args.infile)
print (message)

----------

%%bash

python3 testcipher.py plain_message.txt


----------

如果您要从其他应用程序驱动PPT,请尝试使用此工具。空号。未经测试。告诫执行者:

Sub changeSelectedText()

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

End Sub