我有一个带有以下宏的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)
试试这个:
$ppt = New-Object -ComObject powerpoint.application
$presentation = $ppt.presentations.Open("test.pptm")
$ppt.Run("test", @())