PowerPoint: Launching Other Applications with Command Line Switches

Here's something I meant to mention a while back: did you know that when you set a shape's action setting to launch a program, you can pass command line switches to that program?

This is something I stumbled across, and there doesn't seem to be any mention of it in the PowerPoint 2003 VBA Reference, so until the next update I'm posting the information here.

You can set PowerPoint to perform certain actions, including starting other programs, based on user interaction with a given shape. You do this by specifying a shape's action settings. Each shape can have two actions:

·         One PowerPoint performs when the user clicks the shape.

·         One PowerPoint performs when the user moves the mouse over the shape.

If you specify that PowerPoint should launch another application as one of a shape's action settings, you can also include any command line switches you want PowerPoint to pass to the target application.

Take a look at the code below. It assigns an action setting to the selected shape. The code selects the action PowerPoint performs when the shape is clicked, and sets two of that action's properties. The Action property specifies which action to perform; in this case, run a program. The Run property represents the program name, as well as any command line switches. In this example, we're passing the "/sidenote" command. During a presentation, when the user clicks on the shape, PowerPoint launches OneNote as a new side note.

Sub OpenSideNote()

  With ActiveWindow.Selection.ShapeRange(1) _


    .Action = ppActionRunProgram

    .Run = "onenote.exe /sidenote"

  End With


End Sub

(Wondering what other command line switches are available for OneNote? Oh look, I just happened to write an article about that very subject. How's that for cross-promotion?)

For the code-adverse of you out there, you can also do this through the user interface:

·         Right-click the shape, and select Action Settings.

·         On the Mouse Click or Mouse Over tab, select the Run program button.

·         Enter the application name and command line switches in the text box below the Run program radio button.

Now all I have to do is update the PowerPoint VBA Reference...

Comments (0)

Skip to main content