I have a PowerPoint with the following macro:
Sub test()
MsgBox "testing"
End Sub
And a PowerShell script like this:
$ppt = New-Object -ComObject PowerPoint.Application
$presentation = $ppt.Presentations.Open("test.pptm")
$ppt.Run("test")
But running the macro just gives:
Cannot find an overload for "Run" and the argument count: "1". At line:1 char:1 + $ppt.Run("test") + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest
I get the same error for e.g. $presentation.application.run("test")
and
$ppt.Run("test.pptm!test")
.
Related:
Calling Excel macros from PowerShell with arguments
Passing a variant through COM object via PowerShell to run a macro in PowerPoint
The documentation suggests that Run
should just take the macro name as a string as its first argument, so I can't see where I'm going wrong.
OverloadDefinitions ------------------- System.Object Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams) System.Object _Application.Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams)