2017-01-06 63 views
0

我有下面的宏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

+0

您使用的PPT模板application.run,所以我相信一个逗号,所以app.run functionName,而ARG1,ARG2 https://开头msdn.microsoft.com/en-us/library/office/ff744221.aspx –

回答

2

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

更改此:

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

到这一点:

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