PDA

View Full Version : Running procedures stored in variables



jlingle
02-21-2012, 05:11 AM
Using PowerPoint 2010 I am trying the run a procedure stored in a variable. The procedure is stored in a Module. It looks like others have done this with the "Run" command--at least in Excel. However, when I try to execute the command: "Run tNames(i)" from a control procedure called "InitiateTemplate" I get an error message that says:

"Cannot run the macro 'Cover'. The macro may not be available in this workbook or all macros may be disables"

The procedure is contained in a different Module, but I've doubled checked and it is indeed named "Sub Cover()". Is there a way to call this procedure using a variable name from a procedure in a different module?

Paul_Hossler
02-26-2012, 05:34 PM
Module1


Option Explicit
Dim SubNames(1 To 3) As String
Sub Calling()
SubNames(1) = "Called_1"
SubNames(2) = "Called_2"
SubNames(3) = "Called_3"

Call Application.Run(SubNames(1))
Call Application.Run(SubNames(2))
Call Application.Run(SubNames(3))
Call Application.Run("Called_4", 10, 20, 30)

End Sub


Module2


Option Explicit

Sub Called_1()
MsgBox "Called_1"
End Sub
Sub Called_2()
MsgBox "Called_2"
End Sub
Sub Called_3()
MsgBox "Called_3"
End Sub

Sub Called_4(x As Long, y As Long, z As Long)
MsgBox "Called_4 -- " & x & " -- " & y & " -- " & z
End Sub



Seems to work OK for me

Paul

jlingle
02-26-2012, 06:04 PM
Thanks Paul. I was leaving off the term "Application" before the "Run." Once I added that things worked great.