![]() |
Determine procedure name at cursor?
Hi,
Is there a way to programmatically determine the name of the procedure/function where the cursor is currently located? To explain, suppose a regular VBA module has 3 procedures in it (Foo1, Foo2 & Foo3); my query is if I click anywhere within Foo2 in the code module window, is there any way to determine that I have my cursor currently within Foo2? The reason I need to determine this is to click within any procedure, and then call this procedure from another one using the Application.Run method. Thanks, Amit |
Determine procedure name at cursor?
Hello,
Not that I know of, that'd be a fairly serious hook. If you're actually clicking into a procedure, and you want that procedure to run, why not hammer your f5 key at that point? This will run the procedure where your cursor lies. Regards, Nate Oliver |
Determine procedure name at cursor?
No one? Is this not possible?
Amit Shanker wrote: Hi, Is there a way to programmatically determine the name of the procedure/function where the cursor is currently located? To explain, suppose a regular VBA module has 3 procedures in it (Foo1, Foo2 & Foo3); my query is if I click anywhere within Foo2 in the code module window, is there any way to determine that I have my cursor currently within Foo2? The reason I need to determine this is to click within any procedure, and then call this procedure from another one using the Application.Run method. Thanks, Amit |
Determine procedure name at cursor?
Hi Nate,
The detailed scenario is this: I have written a custom Excel add-in, and among other things, this add-in has a procedure (attached to a button in my VBE IDE) for calculating how long another sub/procedure takes to execute. Ideally, I wish to click within any procedure in an open project that I am working on, and pass it's name to the time calculating procedure in my add-in as an argument to Application.Run("myTestSub"). Thanks for your interest! Amit Nate Oliver wrote: Hello, Not that I know of, that'd be a fairly serious hook. If you're actually clicking into a procedure, and you want that procedure to run, why not hammer your f5 key at that point? This will run the procedure where your cursor lies. Regards, Nate Oliver |
Determine procedure name at cursor?
There are a couple of methods that you need for this: GetSelection, and
ProcOfLine, both of which are in the VBIDE library. The following is extracte from Help for the two methods. You can get the line number from the StartLine argument of the GetSelection method, and if you supply that to GetProcOfLine, it will return the procedure name. The following worked for me from the immediate window: application.vbe.activecodepane.getselection L1&,C1&,L2&,C2& debug.print application.VBE.activecodepane _ .codemodule.ProcOfLine(L1&,vbext_pk_Proc) GetSelection Method Returns the selection in a code pane. Syntax object.GetSelection(startline, startcol, endline, endcol) ProcOfLine Property Returns the name of the procedure that the specified line is in. Syntax object.ProcOfLine(line, prockind) As String On Tue, 15 Mar 2005 15:47:49 -0000, "Amit Shanker" wrote: Hi, Is there a way to programmatically determine the name of the procedure/function where the cursor is currently located? To explain, suppose a regular VBA module has 3 procedures in it (Foo1, Foo2 & Foo3); my query is if I click anywhere within Foo2 in the code module window, is there any way to determine that I have my cursor currently within Foo2? The reason I need to determine this is to click within any procedure, and then call this procedure from another one using the Application.Run method. Thanks, Amit |
Determine procedure name at cursor?
Thanks Myrna, I'll give this a go!
Myrna Larson wrote: There are a couple of methods that you need for this: GetSelection, and ProcOfLine, both of which are in the VBIDE library. The following is extracte from Help for the two methods. You can get the line number from the StartLine argument of the GetSelection method, and if you supply that to GetProcOfLine, it will return the procedure name. The following worked for me from the immediate window: application.vbe.activecodepane.getselection L1&,C1&,L2&,C2& debug.print application.VBE.activecodepane _ .codemodule.ProcOfLine(L1&,vbext_pk_Proc) GetSelection Method Returns the selection in a code pane. Syntax object.GetSelection(startline, startcol, endline, endcol) ProcOfLine Property Returns the name of the procedure that the specified line is in. Syntax object.ProcOfLine(line, prockind) As String On Tue, 15 Mar 2005 15:47:49 -0000, "Amit Shanker" wrote: Hi, Is there a way to programmatically determine the name of the procedure/function where the cursor is currently located? To explain, suppose a regular VBA module has 3 procedures in it (Foo1, Foo2 & Foo3); my query is if I click anywhere within Foo2 in the code module window, is there any way to determine that I have my cursor currently within Foo2? The reason I need to determine this is to click within any procedure, and then call this procedure from another one using the Application.Run method. Thanks, Amit |
All times are GMT +1. The time now is 07:26 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com