我有一个包含以下宏的 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", @())
关于vba - 从 PowerShell 运行 PowerPoint 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41546723/