vba - 从 PowerShell 运行 PowerPoint 宏

标签 vba powershell powerpoint

我有一个包含以下宏的 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)

Application.Run Method (PowerPoint)

最佳答案

试试这个:

$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/

相关文章:

ms-access - 将 SQL 中的纯文本转换为 Access 中的超链接

powerpoint - 在 Powerpoint 幻灯片中插入形状(Office Javascript API)

c# - 每 5 分钟自动在窗口窗体之间随机播放

用于屏幕抓取到数据表的 C# 解决方案?

excel - 使用 Outlook 发送邮件时隐藏屏幕更新

powershell - Azure PowerShell - 设置-AzureService : ResourceNotFound: The hosted service does not exist

正则表达式以匹配 Powershell 中的 URL

excel - VBA 运行时错误 : save PowerPoint Presentation as PDF

vba - 流式传输实时数据时,Worksheet_Change 不会启动

powershell - 如何使用变量存储catch block 的错误类型?