Consulting

Results 1 to 3 of 3

Thread: Running procedures stored in variables

  1. #1
    VBAX Regular
    Joined
    Feb 2012
    Posts
    41
    Location

    Running procedures stored in variables

    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?

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Module1

    [vba]
    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
    [/vba]

    Module2

    [vba]
    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

    [/vba]

    Seems to work OK for me

    Paul

  3. #3
    VBAX Regular
    Joined
    Feb 2012
    Posts
    41
    Location
    Thanks Paul. I was leaving off the term "Application" before the "Run." Once I added that things worked great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •