ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Name of Sub/Procedure? (https://www.excelbanter.com/excel-programming/416886-name-sub-procedure.html)

Charlotte E.

Name of Sub/Procedure?
 
Is it possible to get the name of the current running Procedure?

Kind of an 'ActiveProcedure.Name' request :-)


Thanks,




Mike H

Name of Sub/Procedure?
 
Hi,

Why don't you hardcode the name of the subroutine into each subroutine, it's
only an extra line and you can call it at any time

Sub SubName()
ThisSub = "SubName"
'Lots of other code
End Sub

Mike

"Charlotte E." wrote:

Is it possible to get the name of the current running Procedure?

Kind of an 'ActiveProcedure.Name' request :-)


Thanks,





Charlotte E.

Name of Sub/Procedure?
 
That's a solution, which I considered myself :-)

But something like 'ActiveProcedure.Name' would also be just one line, and
save me from forgetting to write the right name or mispell the name :-)



"Mike H" skrev i en meddelelse
...
Hi,

Why don't you hardcode the name of the subroutine into each subroutine,
it's
only an extra line and you can call it at any time

Sub SubName()
ThisSub = "SubName"
'Lots of other code
End Sub

Mike

"Charlotte E." wrote:

Is it possible to get the name of the current running Procedure?

Kind of an 'ActiveProcedure.Name' request :-)


Thanks,







Mike H

Name of Sub/Procedure?
 
Let's wait for a solution then but I don't know how to do that

Mike

"Charlotte E." wrote:

That's a solution, which I considered myself :-)

But something like 'ActiveProcedure.Name' would also be just one line, and
save me from forgetting to write the right name or mispell the name :-)



"Mike H" skrev i en meddelelse
...
Hi,

Why don't you hardcode the name of the subroutine into each subroutine,
it's
only an extra line and you can call it at any time

Sub SubName()
ThisSub = "SubName"
'Lots of other code
End Sub

Mike

"Charlotte E." wrote:

Is it possible to get the name of the current running Procedure?

Kind of an 'ActiveProcedure.Name' request :-)


Thanks,








ward376

Name of Sub/Procedure?
 
Chip Pearson has info on Referencing VBIDE Objects:

http://www.cpearson.com/excel/vbe.aspx

Cliff Edwards

Dave Peterson

Name of Sub/Procedure?
 
I _think_ that MZTools has a way of doing this typing for you.
http://www.mztools.com/index.aspx

"Charlotte E." wrote:

That's a solution, which I considered myself :-)

But something like 'ActiveProcedure.Name' would also be just one line, and
save me from forgetting to write the right name or mispell the name :-)

"Mike H" skrev i en meddelelse
...
Hi,

Why don't you hardcode the name of the subroutine into each subroutine,
it's
only an extra line and you can call it at any time

Sub SubName()
ThisSub = "SubName"
'Lots of other code
End Sub

Mike

"Charlotte E." wrote:

Is it possible to get the name of the current running Procedure?

Kind of an 'ActiveProcedure.Name' request :-)


Thanks,





--

Dave Peterson

Peter T

Name of Sub/Procedure?
 
To insert at the cursor line -
Const cPROC As String = "myProcedureName"
with alt-P (button on VBE main menu)

Install the following into your personal.xls or some addin, code in a normal
module and also a class named "cVBEbutton"

' code in normal module in personal.xls or addin
Option Explicit
Private clsBtnEvents As cVBEbutton

' call IDEmenus true/false in open/close events, or manually

Sub auto_openX() ' remove the X
IDEmenu True
End Sub
Sub auto_closeX()
IDEmenu False
End Sub

Sub IDEmenu(bCreate As Boolean)
' add a button on VBE's main menue bar and sub-class its click event
Const cPROC As String = "IDEmenus"

On Error Resume Next
Application.VBE.CommandBars(1).FindControl(Tag:="P rocNameButton").Delete
On Error GoTo errH

Set clsBtnEvents = Nothing

If bCreate Then
Set clsBtnEvents = New cVBEbutton
Set clsBtnEvents.VBbutton = _
Application.VBE.CommandBars(1).Controls.Add(1, temporary:=True)
With clsBtnEvents.VBbutton
.Tag = "ProcNameButton"
.Style = msoButtonCaption
.Caption = "&Proc-Name"
.Parameter = "ProcName"
End With
End If

Exit Sub

errH:
'Debug.Print cPROC & " " & Err.Description
End Sub
' end code in normal module


' code in class "cVBEbutton"
Option Explicit
Public WithEvents VBbutton As CommandBarButton

Private Sub vbButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
Const cPROC As String = "vbButton_Click"

Dim nStart As Long ' cursor line
Dim sProcName As String

Select Case Ctrl.Parameter

Case "ProcName"

With Application.VBE.ActiveCodePane
.GetSelection nStart, 0&, 0&, 0&
With .CodeModule
sProcName = Chr(34) & .ProcOfLine(nStart, 0&) & Chr(34)
.InsertLines nStart, "Const cPROC As String = " & sProcName
End With
End With

'Case "some other button tag"

End Select

End Sub
' end code in class cVBEbutton

Obviously adapt to own needs.

Regards,
Peter T

PS - there's no way to trap obtain names in the Stack while code is running.
Can of course break and Ctrl-l


"Charlotte E." wrote in message
...
Is it possible to get the name of the current running Procedure?

Kind of an 'ActiveProcedure.Name' request :-)


Thanks,







All times are GMT +1. The time now is 11:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com