CoolBar or MacroX Code for Floating Toolbar?

T

Tom_OM

I'm writing utility for Word that needs to have a floating and
dockable toolbar. A regular form won't do the trick because the gizmo
is pretty much useless unless the user can edit his/her document while
this toolbar either floats or is docked at the top. This toolbar will
have a few buttons and a combo box from which the user will select
what commands to run.

I've used the Toolbar together with the ImageList ActiveX control
extensively in regular VB 6, but I've never used the Coolbar control.
I've skimmed MSDN and O'Reilly's VB Controls in a Nutshell, and it
appears that you use the inside of the Coolbar to put whatever buttons
you want to onto your floating toolbar, and that the Coolbar is what
allows you to make your toolbar floating or docked.

I have code from a previous VB project that contains subs that help
the user to remove or add buttons to and from a Toolbar. So, is it a
slam dunk that the best approach is for me to use the Toolbar, the
ImageList, and the Coolbar for my VBA project? That's what I'm unsure
about.

First, I'd like to know if there are any gotchas when using ActiveX
controls in VBA. I've only used them in regular VB. Second, I'm
wondering if it's feasible to create this thing without any ActiveX
controls. I searched the news group's archives for "floating toolbar"
and found some code that creates a floating and dockable toolbar with
what is intrinsically available in VBA. (I'm posting it at the end of
this message.)

I'm intrigued. Is it somehow possible to use this code I've found to
programattically instantiate buttons and a ComboBox? If so, what
MSDN/archive search/3rd party VBA material do I need to be reading up
in so that I can get a solid understanding on how to do this?

Or am I better off doing the Toolbar/ImageList/Coolbar thing? I
appreciate any help offered.

cheers,
Tom

The Code:

Option Explicit
Public Sub AutoExit()
'Runs whenever MacroX is unloaded as a global template, or when
'Word exits
'Removes the toolbar
On Error Resume Next
'remove the toolbar if it is still there
CommandBars("MacroXToolBar").Delete
End Sub


Public Sub AutoExec()
'Runs whenever MacroX is loaded as a global template
'Creates the MacroX toolbar
Dim cbb As CommandBarButton


On Error Resume Next
'delete the command bar in case it already exists
CommandBars("MacroXToolBar").Delete


'create toolbar and add a button
On Error GoTo 0
CommandBars.Add("MacroXToolBar").Visible = True
Set cbb = _
CommandBars("MacroXToolBar").Controls.Add _
(Type:=msoControlButton, Before:=1)
With cbb
.Caption = "MacroX"
.FaceId = 630 'a picture for the button, pick any one you
like
.OnAction = "SetUpMacroX"
.Style = msoButtonIconAndCaption 'or choose just to display
Caption
End With
End Sub


Public Sub AutoOpen()
'Executes whenever MacroX is opened
Call AutoExec
End Sub


Public Sub AutoClose()
Call AutoExit
End Sub
 
J

Jezebel

You're dealing with two different issues. The code you've posted relates to
command bars, which is how Word's own menus and toolbars are managed, and
which -- by the sounds of it -- will do what you want. You can create and
remove commandbars, and add and remove controls, at runtime.

Use the Object Viewer to see how commandbars and their controls work. It's
part of the Office model, accessible through Word (as opposed to an
intrinsic part of Word).

VB's controls, such as the coolbar, won't work. Not easily, anyway.
Form-handling is one area where VBA and VB are quite different. There's no
easy way to keep a VBA UserForm active while the user is editing. And for
purposes of selecting commands, it's an unnecessary complication (given that
the CommandBars system is already in place).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top