使用excel vba中的数组和函数调用多个宏

我无法调用其名称存储在字符串数组中的宏.

我附上了代码.

Option Explicit
Option Compare Text

Dim i, Ro As Integer

Public Sub Universal_Macro()

Dim Col(10) As Integer
Dim macro_name(10) As String

Ro = ActiveCell.Row

i = 1

For i = 1 To 10
    Call Mac_Sched(Col(), macro_name())
Next

End Sub

Sub Mac_Sched(Col() As Integer, Internal_Array() As String)
    Cells(Ro, Col(i)).Select
    Call Internal_Array(i)
End Sub

在子Mac_Sched中获取错误.

最佳答案 尝试使用Application.Run:

Sub RunMc()

 Dim a(1 To 2) As String
 Dim MN As String

 For i = 1 To 2 'Fill the array
  a(i) = "m" & i
 Next
 MN = "Module1" 'the module name

 For i = LBound(a) To UBound(a)
  Application.Run MN & "." & a(i)
 Next

End Sub

Sub m1()
 Debug.Print "m1"
End Sub

Sub m2()
 Debug.Print "m2"
End Sub
点赞