Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

programmatically open VBE and go to a specified procedure in target module?

156 views
Skip to first unread message

DataFreakFromUtah

unread,
Jul 8, 2004, 7:04:06 PM7/8/04
to
Hello all,

Win 2000
Excel 2000

I am wondering if there is a way to programmatically open the VBE and
go to a specific
procedure or macro in the target module (in this example: basModule1).
I have the code to go
to the target module, but I can't seem
to figure out a way for the procedure to open at the target procedure
or macro.
I spent some time looking at the object model and searching the
microsoft.public.excel.programming newsgroup, no luck.
Might anyone out there have an answer?
Thank you in advance for any information you may provide.
Cheers,
Tom


Sub OpenVBE()
' Open the Visual Basic Editor Programmatically

Application.VBE.MainWindow.Visible = True
'The next line of code goes to a specified module
ThisWorkbook.VBProject.VBComponents("basModule1").Activate

End Sub

Jake Marx

unread,
Jul 8, 2004, 7:42:49 PM7/8/04
to
Hi DataFreakFromUtah,

I'm not well-versed with the VBE objects, but this seems to work:

Sub OpenVBE()
Dim lStartLine As Long

ThisWorkbook.VBProject.VBComponents("basModule1").Activate

With Application.VBE.ActiveCodePane.CodeModule
lStartLine = .ProcStartLine("test2", 0)
.CodePane.SetSelection lStartLine, 1, lStartLine, 1
End With
End Sub


Just change the "test2" to the name of your procedure.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

DataFreakFromUtah

unread,
Jul 12, 2004, 10:45:54 AM7/12/04
to
Thanks Jake!
I was able to make the procedure work by adding one line of code to
it:
Application.VBE.MainWindow.Visible = True
Apparently the procedure wouldn't work if the VBE wasn't all ready
open.
I am in Win 2000, Excel 2000, with VBE>Tools>References>Microsoft VBA
Extensibility 5.3 checked.
The procedure that worked for me is below:

Sub OpenVBEGoToSpecificMacro()

Dim lStartLine As Long
Application.VBE.MainWindow.Visible = True
ThisWorkbook.VBProject.VBComponents("ModuleNameHere").Activate

With Application.VBE.ActiveCodePane.CodeModule
lStartLine = .ProcStartLine("VBAProcedureNameHere", 0)


.CodePane.SetSelection lStartLine, 1, lStartLine, 1
End With
End Sub


"Jake Marx" <msn...@longhead.com> wrote in message news:<#fofIVUZ...@TK2MSFTNGP11.phx.gbl>...

Peter T

unread,
Jul 12, 2004, 11:17:50 AM7/12/04
to
Have you tried, simply:

Sub Test()
Application.Goto "MyRoutine"
End Sub

Regards,
Peter

>.
>

Jake Marx

unread,
Jul 12, 2004, 12:37:55 PM7/12/04
to
Peter T wrote:
> Have you tried, simply:
>
> Sub Test()
> Application.Goto "MyRoutine"
> End Sub

Nice catch, Peter! I didn't think of that one.

Michael Bishop

unread,
Jun 23, 2022, 3:04:39 PM6/23/22
to
Awesome that the more verbose code works with Class modules.

Auric__

unread,
Jun 23, 2022, 6:25:26 PM6/23/22
to
Michael Bishop wrote:

> Awesome that the more verbose code works with Class modules.

Awesome that you're replying to an 18-year-old post.

> On Monday, July 12, 2004 at 9:37:55 AM UTC-7, Jake Marx wrote:
^^^^^^^^^^^^^

--
If you're smiling, I must be doing something wrong.
-- AppleSeed

Peter T

unread,
Jul 9, 2022, 2:11:56 PM7/9/22
to
On 23/06/2022 23:25, Auric__ wrote:
> Michael Bishop wrote:
>
>> Awesome that the more verbose code works with Class modules.
>
> Awesome that you're replying to an 18-year-old post.

Well it's to see my 18yo posts are still of use:)

Peter T

0 new messages