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?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,978
Messages
5,767,422
Members
425,411
Latest member
sarmientojayexce03

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top