To keep this post from straying off topic, let’s jump here.
Anothe nice touch to putting a Compile button on your VBE toolbar:
If you set the button to display icon & text, the current project name displays
next to the word “Compile”
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Compile Button in VBE (any)
Well,
If you want a VBA 6 (Office 2K or later) add-in that has a button that wil clear the immediate window, have a look at MZtools
I have it on ALL the machines I develop on. Best part, it’s free!!
There are SO many great features about this, I can’t list them all. Just have a look at it, and try it. You’ll like it as much as I do.
No affiliation, other than an end user.
No, we wrote subs to clear the immediate window (none of which work consistently for some unknown reason). I don’t recall any posts about modifying the VBE toolbar to include a button to do it. My oversight if there was one.
My interest back then was to include a call statement to clear the IW in a routine being debugged. It’s tedious having to click on the Immediate window, Ctrl-A, Del after every test run. Since the code to clear the IW doesn’t work, a toolbar button seems to be the next best thing.
Well, Byan’s post about MZTools was just the post I was hoping for. That tool set has such a button.
Maybe smarter programmers can write code that works!
p.s. I’m not being critical of those who wrote the “old” code (I made an attempt, as did Andrew C. not sure who else) ’cause the code does work, but not always.
Here’s a dumb question: How do you add a custom toolbar button in VBE? I don’t see any obvious way to do this when you open “Customize” dialog. For example, you once posted some code that closes all open code pane windows. I use this all the time, call sub using Tools “Macros” command, but it’d be cooler to use custom toolbar button for this. Any ideas??
I just received this link, http://msdn.microsoft.com/library/default….ice07042002.asp[/url], in an e-mail from Microsoft this morning.
Look about halfway down the page. There is a function called, AddCommandBarButtonToVBE
I haven’t read it yet so no review, but I’m planning on reading it soon.
Thanx for the links, I’ll check these out & try code when I get chance. But what I would like to know, since MS makes it simple to add custom buttons, menus, etc thru the UI, w/o any programming required, for application toolbars, why isn’t the same functionality provided for toolbars in VBE??
Mark,
The simple answer to this is that the VBE toolbars are not a part of the Office object model. According to Chip Pearson, the VBE
“… is based on the Visual Basic (Visual Studio) model, not the Office model. ” Translated, that means the VB dev team got lazy
or ran out of time.
I use the Steve Bullens idea (as Brooke mentioned) to create an event handler class. I got started with this page.
[indent]
The simple answer to this is that the VBE toolbars are not a part of the Office object model
[/indent]Actually according to this page from Microsoft, it is part of the Office CommandBar Object, or at least that’s how I interperet it.
Here is a copy and paste from the page:[indent]
Working with command bars in the Visual Basic Editor is similar to working with command bars in the main Office applications. The Visual Basic Editor CommandBars object returns a reference to the Office shared components’ CommandBars collection. Remember to set a reference to the Microsoft Office 10.0 Object Library (if you’re using Microsoft Office XP) if it is not already set, or you will receive a User-defined type not defined error message if your code tries to access the CommandBars collection, command bar objects, or command bar control objects in the Office shared components object library.
[/indent]
Of course, in all fairness to those hard-working MS folks: maybe the VB5 code-base used Windows objects and later versions reference the Office shared objects???
In Word 97, you need a reference to the VBA Extensions library. Looks like Office 10+ needs a reference to the Office 10 Object Library. My install of Office XP has that reference set by default.
Updated after reading the msdn paged you referenced:
“To access the Visual Basic Editor object model, you must first set a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 type library.”
That’s MS for you. Chip Pearson and Steve Bullens have it figured out. You need the events handler, period.
Try my code based on gleanings from these two guys and others.
Attached to this message is the code mod (rename .txt to .bas and import). Attached to the next message is the class mod.
I’m glad I’m not the only one that does things as programming exercises.
I am currently working on a VBA “application” (hopefully it will work in Word, Excel, and any other VBA enabled application) to list ALL variables in a VBA Project. It started as a request from someone on a Word list I belong to, as a way to start to get a handle on how to work with the VBE, and it’s taken on a life of its own
Well, If you want to see V1 RC2, you can get it from http://www3.sympatico.ca/carbonnb/dwt/index.html%5B/url%5D.
It doesn’t handle Let/Get/Set properly and it misses conditionally compiled stuff properly at the moment. These are the areas I’m working on right now.
Dumb question? Are you kidding? That’s an extremely intelligent question. See my other response to your post below. If you need any help after checking out my reference and the others mentioned, feel free to ask more questions.
If you can figure out how to make this work consistently, I’d appreciate seeing the “ClearImmediate” code:
Sub TestRoutine
Call ClearImmediate
Do
AllSortsOfThingsToTestWhichWriteToThe(“Debug”, “Window”)
Loop Until Done
End Sub
Thanx for additional info. I used MZ-Tools with VBE in Office 2K & worked good, the “Clear Immediate WIndow” button at any rate functioned as advertised. Have not used them in Office XP. So maybe I’ll just be lazy (like those lazy MS VB/VS dev guys) & download & install MZ-Tools – do they work OK with VBE in Office XP??
Since previous post I installed MZ-Tools on Office XP system & the add-in works fine w/no problems. I’d forgotten what a cool (and useful) product this is. I’d ask, why doesn’t MS incorporate many of these features in VBE, rather than having users resort to using 3rd-party add-ins, but that’d be another dumb question.
(Edited by HansV to update link to Excel MVP site)
I believe the only way to do this is programattically and to use a class module to trap the click events of the custom buttons. I just use Stephen Bullens VBEtools2000 as is, which is available from http://www.BMSLtd.ie[/url%5D. This is not locked so you can use it as a tuition for how to roll your own.
Kevin,
I’ve just been reading the Clear Immediate Window posts, which I must have missed the first time round, and it seems to me that if you’re going to use SendKeys, you might as well just use:
SendKeys “^g^a{del}”
Unfortunately this still doesn’t seem to work correctly if you call it to clear the window before printing some more stuff to it – at least in my test it removed everything including the new debug info!
FWIW.
Rory,
Nice pic. Too bad we can’t embed mp3s in Lounge posts (oh yeah, right!). We’d all be searching for your posts just to get an Elvis fix (no pun intended) Heartbreak, Love Me, Blue Suede…
I’ve tried various renditions of strings to pass to Sendkeys and the one published seemed the most consistent (besides, Andrew Connolly showed me this one).
What’s happening for you is this: the immediate window does not have focus, so you are clearing one of your code windows!!
I’ve also done extension testing with focus setting, using Sendkeys, the .setfocus method on the window object and API calls (getfocus, etc.)
You’ve got to separate the ^g (setting the focus) from the ^a{del}. Not sure why, but it’s obvious the ^g is not working (or at least is inconsistent).
By the way, this much is conclusive:
Calling a ClearImmediate sub from another sub simply does not work.
But calling the ClearImmediate sub from a VBE command button works every time!
–AND YES, CHARLOTTE, IT’S THE EXACT SAME CODE (NO SUPERIOR PROGRAMMER REQUIRED)
Interestingly, when creating the button, you can indicate an accelerator key. Executing
the commandbutton by pressing the accelerator key — DOES NOT WORK!
I suspect this inconsistency is all due to “focus” issues. Maybe sending keystrokes to the
window using an API call might work.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications