简体   繁体   English

如何创建一个宏并依次运行多个宏?

[英]How to create a macro and run multiple macros consequentially?

I have an excel workbook with five different recorded macros on five different sheets.我有一个 excel 工作簿,在五个不同的工作表上有五个不同的录制宏。 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.谢谢你。

As explained in this question : Multithreading in VBA cannot be done natively.正如在这个问题中所解释的:VBA 中的多线程无法本机完成。

Can't be done natively with VBA.不能用 VBA 本地完成。 VBA is built in a single-threaded apartment. VBA 内置于单线程单元中。 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.获得多个线程的唯一方法是在具有 COM 接口的 VBA 之外的其他东西中构建一个 DLL 并从 VBA 调用它。

So running all 5 macros at the same time would require a lot of work.因此,同时运行所有 5 个宏需要大量工作。

But OP mentioned in the comment that running all 5 macros sequentially would be an option.但是 OP 在评论中提到按顺序运行所有 5 个宏将是一种选择。

What you can do is:你可以做的是:

  1. Add a new module添加新模块

添加新模块

  1. Add a new public sub in this module在这个模块中添加一个新的公共子

添加一个新子

  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.现在运行这个宏将按顺序运行所有指定的宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM