Results 1 to 20 of 21

Thread: VBA Application.Run for Running Macros-with-Parameters Stored Inside an Excel Cell

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    Assuming that the cells contain EITHER a macro name OR a Macro Name and 2 Parameters, and nothing else:

    Something like...
    Option Explicit
    
    Sub SelectAppsToRun()
    Dim rng As Range 'rng only contains Strings, your 'Macros" must deal with Strings
    Dim Arr
    
        For Each rng In Sheet1.Range("A1:A5")
            Arr = Split(rng, ", ") 'The Split parameter depends on the textual formatting of the contents of the cell.
                                   'I am assuming a Comma & Space separates each "value"
            If Not IsArray(Arr) Then
                Application.Run rng.Value
            Else
               Application.Run Arr(0), Arr(1), Arr(2)
            End If
        Next rng
    
    End Sub
    See how much easier it is to just use VBA:
    Sub RunAllFive()
       Macro1
       Macro2 Sheets("Sheet1"), TextBox2
       Macro3
       Macro4 Sheets("Sheet2"), Texbox1
       Macro5
    End Sub
    Last edited by SamT; 05-14-2021 at 08:12 AM.
    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

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