从PowerShell运行PowerPoint宏

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

我有一个带有以下宏的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)

vba powershell powerpoint
1个回答
0
投票

试试这个:

$ppt = New-Object -ComObject powerpoint.application
$presentation = $ppt.presentations.Open("test.pptm")
$ppt.Run("test", @())
© www.soinside.com 2019 - 2024. All rights reserved.