gpt4 book ai didi

vba - 从 PowerShell 运行 PowerPoint 宏

转载 作者:行者123 更新时间:2023-12-05 07:45:30 24 4
gpt4 key购买 nike

我有一个包含以下宏的 PowerPoint:

Sub test()
MsgBox "testing"
End Sub

还有一个像这样的 PowerShell 脚本:

$ppt = New-Object -ComObject PowerPoint.Application
$presentation = $ppt.Presentations.Open("test.pptm")
$ppt.Run("test")

但是运行宏只会给出:

Cannot find an overload for "Run" and the argument count: "1".At line:1 char:1+ $ppt.Run("test")+ ~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [], MethodException    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

我得到同样的错误,例如$presentation.application.run("test")$ppt.Run("test.pptm!test")

相关:

Calling Excel macros from PowerShell with arguments

Passing a variant through COM object via PowerShell to run a macro in PowerPoint

文档建议 Run 应该只将宏名称作为字符串作为它的第一个参数,所以我看不出哪里出错了。

OverloadDefinitions-------------------System.Object Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams)System.Object _Application.Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams)

Application.Run Method (PowerPoint)

最佳答案

试试这个:

$ppt = New-Object -ComObject powerpoint.application
$presentation = $ppt.presentations.Open("test.pptm")
$ppt.Run("test", @())

关于vba - 从 PowerShell 运行 PowerPoint 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41546723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com