+ Reply to Thread
Results 1 to 2 of 2

Calling routine with name stored in string variable

Hybrid View

  1. #1
    Registered User
    Join Date
    09-18-2003
    Location
    Denmark, Europe
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    5

    Calling routine with name stored in string variable

    I need some VBA like this:

    Dim AllSubs(1 To 3) As String
     
    Sub myMAIN()
    AllSubs(1) = "Sub1"
    AllSubs(2) = "Sub2"
    AllSubs(3) = "Sub3"
    Call Call_VBA(2) ' This should call a Sub2.
    End Sub
     
    Sub Call_VBA(ByRef I As Integer)
    Dim mySub As String
    mySub = AllSubs(I)
    Call mySub ' Of course this will not function!
    End Sub
     
    Sub Sub1(): MsgBox "Sub1": End Sub
    Sub Sub2(): MsgBox "Sub2": End Sub
    Sub Sub3(): MsgBox "Sub3": End Sub
    Is it at all possible to make a such 'dynamic' call of a VBA routine.
    Last edited by Helge; 05-17-2011 at 03:51 AM. Reason: Added Code Tags
    Helge V. Larsen

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dynamic VBA program

    Sub snb()
      j=1
      application.run "macro_" & j
    End sub
    or
    Sub snb_002()
      sn=array("macro1","macro2","macro_3")
      application.run sn(2)
    End Sub
    Last edited by snb; 05-16-2011 at 12:09 PM.



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1