Word2000: Add a Customer Command Bar to a UserForm

V

VBA Coder

How can I attach a custom command bar to a particular form using VBA? When
my UserForm loads, in my Initialize routine, I'd like to call the following
AddMenuBar subroutine that will create a temporary Command Bar for that
Form. I am able to get it to create a command bar, but can't seem to get it
associated with the form - it floats on the screen.


Private Sub AddMenuBar()
Dim customBar As CommandBar
Dim newButton As CommandBarButton


Set customBar = CommandBars.Add("Custom", , , True)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Cut").ID)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Copy").ID)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Paste").ID)
customBar.Visible = True


End Sub
 
P

PeterS

-----Original Message-----

H'ye,
How can I attach a custom command bar to a particular
form using VBA? When my UserForm loads, in my
Initialize routine, I'd like to call the following
AddMenuBar subroutine that will create a temporary
Command Bar for that Form. I am able to get it to
create a command bar, but can't seem to get it
associated with the form - it floats on the screen.

If I'm reading you correct, this could be what you are
trying to do.
http://rtsoftwaredevelopment.de/Beispiele/Beispiele%
200036.htm
(The page is in German, but you should be able to read the
code. Copy the code to a user form, put a listbox on it,
and step through the code.)

See ya
Peter
 
P

PeterS

-----Original Message-----
Oops, forgot to tell you the first three Subs go into a
normal module. (But I'd think you'd figured that out for
yourself. :) )

See ya
Peter
 
V

VBA Coder

No, that is not what I wanted to do. That creates a popup menu when I
right-click on the list box item which in turns either changes the form
caption or displays a message box when the item is clicked. What I want to
do is have a menu that is at the top of the Form, such as those with File,
Edit, View, Insert, etc..., right below the Form's Menu Bar.
 
J

Jonathan West

VBA Coder said:
No, that is not what I wanted to do. That creates a popup menu when I
right-click on the list box item which in turns either changes the form
caption or displays a message box when the item is clicked. What I want to
do is have a menu that is at the top of the Form, such as those with File,
Edit, View, Insert, etc..., right below the Form's Menu Bar.

Unlike VB Forms, VBA UserForms don't have that capability built-in. It might
be possible to use Windows API commands to hack something like that into
them, but I'm not aware of anybody that has done it.

The simplest option will be to write your form using VB6, in a project saved
as an ActiveX DLL, and then reference the DLL from a macro.

There may be a wholly different approach to this with a different UI. What
is your form supposed to be doing?
 
V

VBA Coder

I wanted to give the user a very simple Menu Bar, with only a few options
such as File/Close/Exit. I'll decide later what else to put on it once I
was able to get a simple menu on my form. I don't want it to be a popup or
a floating menu bar. I want it to be part of the Form.
 

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