将参数传递给子例程

时间:2017-01-06 10:00:38

标签: vba vbscript

我有一个带有以下宏的powerpoint文件:

Sub test(msg$)
    MsgBox msg
End Sub

我有一个看起来像这样的vbscript文件:

Option Explicit
On Error Resume Next
RunMacro

Sub RunMacro()

    Set ppApp = CreateObject("Powerpoint.Application")
    Set ppPres = ppApp.Presentations.Open("test.pptm", 1)

    ppApp.Run "test.pptm!test ""my message here"" "

    ppApp.Quit

    Set ppPres = Nothing
    Set ppApp = Nothing
End Sub

但我似乎无法将字符串参数传递给宏(PPT中没有显示消息框)。我猜测引号的数量是错误的,但我已经尝试了我能想到的每一种排列,没有任何效果。如果我在宏中对消息进行硬编码,一切正常。

相关(试过这些,没有运气)

How to call Run() with parameters

Shell.Run with arguments

1 个答案:

答案 0 :(得分:2)

如有疑问,请阅读documentation。您将(VBScript)WshShell.Run方法与(VBA)Application.Run方法混淆了。

改变这个:

ppApp.Run "test.pptm!test ""my message here"" "

进入这个:

ppApp.Run "test.pptm!test", "my message here"
相关问题