调用范围/列表中的macros
请用下面的代码来帮助你:
1)目标:运行在一个范围内引用的macros。
2)范围(“B1:B101”)包含要运行的macros的列表。 例如,单元格B1包含引用macros名称相同的单词Macro1,B2引用Macro2等等。
3)Macro1,Macro2 …已被创build。
4)我已经在下面的代码,但没有运气呢:
Dim mCell As Range Dim mRange As Range Dim mMacro As String mMacro = mCell.Value Set mRange = Sheets("Sheet1").Range("B1:B101") For Each mCell In mRange.Cells Application.Run Module2.mMacro Next mCell
在你的代码中做一些修改,检查是否你想要:
Sub try() Dim mCell As Range Dim mRange As Range Dim mMacro As String Set mRange = Sheets("Sheet1").Range("B1:B101") For Each mCell In mRange.Cells mMacro = mCell.Value Application.Run "Module2." & mMacro Next mCell End Sub
Application.Run
方法将一个String
作为参数,尝试将该名称作为string传递:
Application.Run "Module2." & mCell.Value