Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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,





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop a Procedure from another procedure Ayo Excel Discussion (Misc queries) 1 October 30th 08 01:42 AM
How to jump from a Form procedure to a Workbook or Module procedure? T. Erkson Excel Programming 4 January 25th 07 07:15 PM
Calling a procedure in a procedure Norman Jones Excel Programming 8 August 20th 04 07:53 PM
Calling a procedure in a procedure N10 Excel Programming 2 August 18th 04 12:49 AM


All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"