2017-01-06 65 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"