使用批处理参数调用powerpoint宏

时间:2012-03-27 04:47:24

标签: vba batch-file powerpoint powerpoint-vba

我想从我的批处理文件中调用一个powerpoint宏,就像这样

"c:\program files\microsoft office\office14\POWERPNT.exe" /M x5_template.pptm macro_name(argument)

问题是它在没有参数的情况下工作正常,但我的要求是传递参数。关于它的任何文字如何传递论证?

2 个答案:

答案 0 :(得分:1)

另一种方法:编写一个在命令行上接受参数的EXE。 然后EXE调用PowerPoint并调用宏并传递任何必要的参数。 这是一个可能有用的VB片段:

Dim oPPTapp As Object
Set oPPTapp = New PowerPoint.Application

' make it visible if need be
oPPTapp.Visible = True  

If Err.Number <> 0 Then
    oPPTapp.Quit
    Set oPPTapp = Nothing
    Exit Sub
End If

' Call PPT VBA subroutine using Parameter, which you've
' parsed from the command line
oPPTapp.Run "NameOfSubRoutine", Parameter

如果您使用第一个命令行parm作为要运行的宏的名称,然后将任何其他parm作为参数传递,则可以使它更通用

答案 1 :(得分:0)

AFAIK你不能。

但是,我使用以下策略来解决一些非常简单的情况。它可能不足以满足您的需求,因为它需要事先规划所有可能的参数。

假设我有一个带有一个String参数的宏ChangeAllFont(newfont as String)

我声明了几个实用程序宏,它们使用一些所需的参数调用宏。例如,

Sub ChangeAllFontArial()
 Call ChangeAllFont("Arial")
End Sub

Sub ChangeAllFontTimes()
 Call ChangeAllFont("Times New Roman")
End Sub

然后我可能会以

的形式调用powerpoint
POWERPNT /M template.ppt ChangeAllFontArial

POWERPNT /M template.ppt ChangeAllFontTimes
相关问题