Eventhandler VBE

BartH

New Member
Joined
Jul 4, 2006
Messages
4
Hello,

In this post (http://www.mrexcel.com/forum/showthread.php?t=39411) Tom Schreiner shows us a variation on Chip Pearson's VBE explanation, to run a procedure with a custom made command in the VBE menu or toolbar.

I am experimenting with this and run into the following problem:

I want to add a string to the current module. This is no problem as long as I fire the procedure from within itself (hit F5). When I address the procedure to a VBE Command item, I am able to only run it once. Also other Custom Commands become inactive, so I suspect the VBIDE.CommandBarEvents is stopped by something. When I change the code to display the string as debug.print, I can run the procedure from the custom made command without any problem.

My testcode is:

Sub Test()
' Inserts string to first line of module (but only once when fired from custom command)
Application.VBE.ActiveCodePane.CodeModule.InsertLines 1, "' Time: " & Time
End Sub

Change that to

Sub Test()
Debug.Print "'Time: " & Time
End Sub

and I can run it endlessly.

Any ideas?
 

Forum statistics

Threads
1,085,986
Messages
5,387,112
Members
402,042
Latest member
snowballresource02

Some videos you may like

This Week's Hot Topics

Top