Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Call a macro in another presentation and pass it parameters

Problem

You're writing code in one PowerPoint add-in or a VB or other project and need to call a subroutine or function in another PowerPoint file or add-in. You also need to pass one or more parameters to the other subroutine or function.

Solution: Application.Run

You can use Application.Run to call subroutines and functions in other presentations or add-ins, or use it from e.g. an external VB program to run PPT macros. As a demonstration, create two presentations.

Include this subroutine in the first presentation:

Sub CallAnotherSubroutine()

    ' Array required to pass parameters
    Dim Params(1 To 2) As String

    Params(1) = "Hi, my name is Steve"
    Params(2)="Whatever else"
    ' and of course you could dim the array to hold more params if you wish

    ' Trigger a macro in a different open presentation; 
    ' For sanity's sake, you'll want to give the sub a unique name
    Application.Run "UniqueName", Params

End Sub

Include this subroutine in the other presentation:

Public Sub UniqueName(params)
    MsgBox params(1)
    MsgBox params(2)
End Sub

Now when you run CallAnotherSubroutine it calls UniqueName from the other presentation, passes it the two parameters you've defined, and UniqueName displays them.

This works for "pushing" parameters to another subroutine or function. What if you want to "pull" information from a subroutine in another project? PowerPoint MVP Shyam Pillai explains how to do that here:

Inter-presentation communication using a function

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Call a macro in another presentation and pass it parameters
http://www.pptfaq.com/FAQ00403_Call_a_macro_in_another_presentation_and_pass_it_parameters.htm
Last update 04 January, 2017
Created: