TBBH,我真不知道你想實現什麼和重編校代碼無助於顯示出比其他企圖具體方法在調用從數組元素衍生出的字符串的宏。
的Application.OnTime method使用一個字符串作爲調用程序的名稱。
Option Explicit
Option Compare Text
Dim i As Integer, Ro As Integer
Sub zero()
Debug.Print "zero: " & i
End Sub
Sub first()
Debug.Print "first: " & i
End Sub
Sub second()
Debug.Print "second: " & i
End Sub
Sub third()
Debug.Print "third: " & i
End Sub
Public Sub Universal_Macro()
Dim Col() As Integer
Dim macro_Name As Variant
macro_Name = Array("zero", "first", "second", "third")
ReDim Col(UBound(macro_Name))
For i = LBound(macro_Name) To UBound(macro_Name)
Col(i) = i
Next
Ro = ActiveCell.Row
For i = LBound(macro_Name) To UBound(macro_Name)
Call macro_Sched(Col(i), macro_Name)
Next
End Sub
Sub macro_Sched(c As Integer, internal_Array As Variant)
Cells(Ro, c + 1).Select '<~~Don't rely on Select! You dont' even reference a worksheet here.
Application.OnTime Now, internal_Array(c)
End Sub
如果參數是要傳遞給孩子Sub過程,然後某種形式的字符串替換的可能適應這一點,但對孩子潛艇細節並非是顯而易見的。
見How to avoid using Select in Excel VBA macros更多的方法從依靠選擇越來越遠,並激活,以實現自己的目標。
你沒有資格'cells'或通過'i'。 – findwindow
在這裏得到錯誤調用Internal_Array(i)它說預期的子或函數或屬性 –
你不能''調用'一個字符串。試着看一下在'CallByName' –