Storing Macro Names in and Calling From an Array

Drofidnas

Board Regular
Joined
Jun 30, 2004
Messages
126
Is this possible?

In a master file I have :

  Sub Open_Block_15()

  On Error Resume Next

  'Define Source Workbook

  DMRLSource = "\Block 15 DMRL.xls"
  SheetSource = "AES"

  'Open Source Workbook and correct tab
  Workbooks.Open Filename:=DMRLSource
  Sheets(SheetSource).Select

  iUpdate = 1
  changeSht = "Block_15"

  End Sub


This is one of 20 Blocks run from 20 buttons.
They all open up separate files maintained by other users.

I also have 20 other macros which import just a few columns from the same workbooks into the master file I am in.

What I then want to do is store the names of the macros associated with these updated files in an array and call them when I revisit my master file.
ie. if I open up 5, 7 and 20, when I go into the master I have a pop up asking me if I want to re-import the new columns from these 3.

I was trying to do this with the changeSht variable - that is what that is doing there.

I already have the MsgBox pop up working and the variable iUpdate is the flag that this particular macro has been run.

How, if at all, could I store up to 20 different names in an array and call them all at once?

Massive thanks to anyone who can a. Understand this and b.provide a solution.

Thanks

Chris
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Assuming an array called MacroNames, you can use a loop like this:
Code:
for n = lbound(macronames) to ubound(macroNames)
   application.run macronames(n)
next n
 
Upvote 0
Thanks Rory

Struggling to update that array each time as it needs to be a global variable I think, as it's being referenced in different macros.
 
Upvote 0
Sorted now thanks.
You put me on the right path

Code:
For x = 1 to 20
Application.Run macronames(x)
Next x

with a

Code:
Global iUpdate As Integer
Global macronames(20) As String

Function access_global()
    iUpdate = 0
    macronames = ""
    
    End Function

in a module.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,739
Members
449,050
Latest member
excelknuckles

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
Back
Top