0
votes

I have an excel workbook with five different recorded macros on five different sheets. Is it possible to create another macro and run those five macros consequentially?

The difficulty is those macros are not specified to each worksheet. I have to run those macros each time manually.

Any thoughts are appreciated! Thank you.

1
By "at the same time" do you mean that they HAVE to run concurrently or is it ok if the macro run sequentially?GTPV
Because concurrently isn't, strictly speaking, possible with single-threaded vba...Mistella
It would be easier to have the five different macros in a normal module that reference the five sheets and call them from there.Darren Bartrup-Cook
Hi @GTPV, consequentially works for me.Boomshakalaka
@Darren Bartrup-Cook, because I recorded those macros for formats, the codes are really big.Boomshakalaka

1 Answers

3
votes

As explained in this question: Multithreading in VBA cannot be done natively.

Can't be done natively with VBA. VBA is built in a single-threaded apartment. The only way to get multiple threads is to build a DLL in something other than VBA that has a COM interface and call it from VBA.

So running all 5 macros at the same time would require a lot of work.

But OP mentioned in the comment that running all 5 macros sequentially would be an option.

What you can do is:

  1. Add a new module

Add a new module

  1. Add a new public sub in this module

add a new sub

  1. Reference all macro names in this sub

Example of how this macro could look like:

Public Sub allMacros()
    macroName1
    macroName2
    macroName3
    Sheet1.macroNameNotUnique
    Sheet2.macroNameNotUnique
End Sub

Now running this macro will run all the specified macros sequentially.