我尝试过类似的方法:
sub tester()
'do something
End Sub
activesheet.cells(1,1) = 'tester'
sub foo()
dim x as string
x = activesheet.cells(1,1).value
Call x
End Sub
目的是操纵一个单元格,以便当单元格值发生变化时,调用的子函数也会发生变化。
最佳答案
使用Application.Run
- 这里有一个错误处理示例,值得花点时间。
Option Explicit
Sub Test1()
MsgBox "First"
End Sub
Sub Test2()
MsgBox "Second"
End Sub
Sub Foo()
On Error GoTo ClearError
Dim S As String: S = CStr(Range("A1").Value)
Application.Run S
ProcExit:
Exit Sub
ClearError:
MsgBox "Run-time error '" & Err.Number & ":" & vbLf & Err.Description
Resume ProcExit
End Sub
关于excel - 是否可以使用字符串动态调用subs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71332847/