我有一个带有以下宏的PowerPoint:
Sub test()
MsgBox "testing"
End Sub
以下是类似于这样的PowerShell脚本:
$ppt = New-Object -ComObject PowerPoint.Application
$presentation = $ppt.Presentations.Open("test.pptm")
$ppt.Run("test")
但是运行宏却出现以下错误:
找不到重载 "Run" 和参数计数: "1". 在 line:1 char:1 + $ppt.Run("test") + ~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest
例如,$presentation.application.run("test")
和$ppt.Run("test.pptm!test")
也会出现相同的错误。
相关链接:
通过PowerShell通过COM对象传递变量以运行PowerPoint中的宏
文档建议Run
方法应该只需要将宏名称作为其第一个参数,所以我看不出哪里出了问题。
重载定义 ------------------- System.Object Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams) System.Object _Application.Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams)