【发布时间】:2017-01-09 11:13:01
【问题描述】:
我有一个带有以下宏的 PowerPoint:
Sub test()
MsgBox "testing"
End Sub
还有一个像这样的 PowerShell 脚本:
$ppt = New-Object -ComObject PowerPoint.Application
$presentation = $ppt.Presentations.Open("test.pptm")
$ppt.Run("test")
但运行宏只会给出:
找不到“运行”和参数计数的重载:“1”。
在行:1 字符:1
+ $ppt.Run("测试")
+ ~~~~~~~~~~~~~~~~
+ 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 应该只将宏名称作为字符串作为它的第一个参数,所以我看不出哪里出错了。
重载定义 ------------------ System.Object Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams) System.Object _Application.Run(string MacroName, [ref] Params System.Object[] safeArrayOfParams)
【问题讨论】:
-
尝试传递一个空数组作为第二个参数?顺便说一句,您可能必须将“ModuleName.SubName”作为第一个参数
标签: vba powershell powerpoint