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.