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

PachRedoc

New Member
Joined
May 14, 2021
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Aim: To Loop Through Cells Containing Macro Names and Run Those Macros via Application.Run

Issue: The code used to loop through cells and run macros works perfectly only for macros without parameters. For those macros with parameters, it fails.

Problem in Detail:

I have stored a few macro names inside Excel cells.

I loop through those cells and call macros (names) written inside them as follows.

[The subroutine below is called from another subroutine by providing the parameters correctly.]

VBA Code:
Sub SelectAppsToRun(ctlGrpName As String,  ws As Worksheet, activeTbx As MSForms.TextBox)

       Dim rng as Range

           For each rng in Sheet1.Range(“A1:A5”)

               Application.Run rng.value

           Next rng

    End Sub

It works correctly when there are no parameters for the macros. But generates error when it tries to run the following macro stored in a cell.

JumpToNextCtl, ws, ctlGrpName, activeTbx

This macro is supposed to take its parameters - ws, ctlGrpName and activeTbx - from the subroutine 'SelectAppsToRun'
ws as Worksheet, ctlGrpName as String, activeTbx As MSForms.TextBox


The error message I get is:

Cannot run the macro '"JumpToNextCtl", ws, ctlGrpName, activeTbx'. The macro may not be available in this workbook or all macros may be disabled.

I understand Application.Run considers the whole as a single string and the fact that there are commas in it does not treat them as separate parameters.

Is there any way to accomplish what I aim to accomplish?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA Application.Run for Running Macros-with-Parameters Stored Inside an Excel Cell
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 

PachRedoc

New Member
Joined
May 14, 2021
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
The following are the links to my cross-posts for the same query.



 

Forum statistics

Threads
1,147,482
Messages
5,741,407
Members
423,657
Latest member
Medrok2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top