VB5 source editor add-in?

I would like to create a menu-item or function-button (or like) that would work within the VB5 editor.  For example... the user could highlight a variable or string in their source code (in VB5 editor)... then execute a function that could insert a new line of code (following the highlighted string).  The new line of code would contain the highlighted string.

Does anyone have example code that does anything like this (in part or in whole)?

p.s. I already know how to programmatically edit the source code outside of the VB5 editor.  
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


To access the main menu of the Visual Basic window, you can use:


This expression returns an object of type

To Add menu-item, here an example for you how to add to the Edit menu "My Item"

Dim MyItem as Office.CommandBarControl
Dim i as Integer

For i=1 to _

  If _
VBInstance.CommandBars.Item(1).Controls("Edit").Control(i).Caption = "My Item" then
      Exit Sub
  End If

Set MyItem = _

MyItem.Caption = "My Item"

End Sub

I hope that it'll help you !!!

alanlAuthor Commented:
Thanks for answering half of the question... but how can detect text selection and insert a new line of text into the source edit window?
I don't know how to detect text selection in CodeModule I don't see any search on text selection.  But you can try to inverstigate in  ...CodeModule.Methode.????

For insert a new line :

VBInstance.ActiveVBProject.VBComponents.Item(1).CodeModule.InsertLine LineNumbre, TEXT

In help file you have:
Application.VBE.CodePanes(1).CodeModule.InsertLines 1, "Option Explicit"

Other methods you have in CodeModule Object are
InsertLine(lineNumber, codeLine)
ReplaceLine(lineNumber, codeLine)
CreateEventProc(eventName, objectName)

The basic properties of the CodeModule Object are
Lines(startLine, count)
ProcBodyLine(procedureName, procedureType)
ProcCountLines(procedureName, procedureType)
ProcOfLine(Line, procedureType)

The number of code components in a project component is given by the following expresion:


This is the number of items in the Members collection.  To access each code component, you must access a specific item of the collection and read its Type property.  The full expression is



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alanlAuthor Commented:
Thanks for all of your effort.
Bought This Question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.