gpt4 book ai didi

vba - 在Excel VBA中使用数组和函数调用多个宏

转载 作者:行者123 更新时间:2023-12-02 11:38:01 25 4
gpt4 key购买 nike

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

我附上代码。

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

关于vba - 在Excel VBA中使用数组和函数调用多个宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34296241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com