要这样动态取得过程的名称感觉比较难,因为代码很难知道程序运行到了哪一行
Function GetProcName() As String
' 只适用于从VBE里直接运行,得到的是光标所在位置的过程名称
Const vbext_pk_Proc As Long = 0 ' 也可以改为引用Microoft Visual Basic for Application Extensibility x.x
Dim m As Long, n As Long, x As Long, y As Long
Application.VBE.ActiveCodePane.GetSelection m, n, x, y ' 取得选定区(光标所在)
GetProcName = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(m, vbext_pk_Proc) '取得过程名称
End Function
Sub Test1()
MsgBox GetProcName
End Sub
Sub Test2()
MsgBox GetProcName
End Sub
Sub Test3()
MsgBox GetProcName
End Sub
|