在下面的代码中,我想循环引用一个函数。函数的名称应从InputDateRange更改为InputDateRange1..2..3.。 不幸的是,我将引号(“ InputDateRange1”)中的字符串作为变量C的值。如何获取C作为InputDateRange1-不带引号? 预先感谢您的答复 DP
For j = 1 To 3
C = "InputDateRange" & j
With DataSet
.Close
.Source = C
.Open
End With
Range("G4").CopyFromRecordset DataSet
Next
答案 0 :(得分:0)
您可以使用Application.Run
。
说下面是该工作簿的模块1。注意,我不是故意使用返回值。
Option Explicit
Public Sub Test()
Dim i As Long, C As String
For i = 1 To 2
C = "Msg" + CStr(i)
Application.Run "Module1." & C
Next
End Sub
Public Function Msg1() As Long
MsgBox "I am msg 1"
Msg1 = 1
End Function
Public Function Msg2() As Long
MsgBox "I am msg 2"
Msg2 = 2
End Function