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

Word2000: Add a Customer Command Bar to a UserForm by PeterS

PeterS
Fri Dec 12 23:11:48 CST 2003

>-----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

Word2000: Add a Customer Command Bar to a UserForm by PeterS

PeterS
Fri Dec 12 23:14:15 CST 2003


>-----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

Re: Word2000: Add a Customer Command Bar to a UserForm by VBA

VBA
Mon Dec 15 07:46:44 CST 2003

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.


"PeterS" <anonymous@discussions.microsoft.com> wrote in message
news:067701c3c137$9c41b5e0$a101280a@phx.gbl...
> >-----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



Re: Word2000: Add a Customer Command Bar to a UserForm by Jonathan

Jonathan
Mon Dec 15 08:32:54 CST 2003


"VBA Coder" <noone@account.com.NO_SPAM.> wrote in message
news:uQfBiHxwDHA.2308@TK2MSFTNGP11.phx.gbl...
> 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?

--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup


Re: Word2000: Add a Customer Command Bar to a UserForm by VBA

VBA
Mon Dec 15 14:01:13 CST 2003

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.


"Jonathan West" <jwest@mvps.org> wrote in message
news:udVEFvxwDHA.2452@tk2msftngp13.phx.gbl...
>
> "VBA Coder" <noone@account.com.NO_SPAM.> wrote in message
> news:uQfBiHxwDHA.2308@TK2MSFTNGP11.phx.gbl...
> > 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?
>
> --
> Regards
> Jonathan West - Word MVP
> http://www.multilinker.com
> Please reply to the newsgroup
>