Commandbar questions about .OnAction and msoFloating

B

Benjamino5

I have two questions about Commandbars I haven't yet found answers to. Any
tips would be greatly appreciated!

1) I want several CommandBarButtons to call the same subprocedure, but with
different arguments. Yet it seems you can't put arguments in the .OnAction
property--you can only put the name of a sub in there. So how do you make a
button call a sub and also pass it an argument?

I'm guessing the Parameter property might be the answer, but I don't know
how to use it, so a code sample would really help me.

2) When creating a floating palette (commandbar with the property
"msoFloating"), I want the buttons on it to be arranged vertically, one on
top of the next, NOT horizontally. How do I do this? The .Width property of a
commandbar is apparently read-only, so I can't set it.
 
H

Helmut Weber

Hi Benjamin,

have a look at these,
just to get you started:

Sub Button1(): Doit 1: End Sub
Sub Button2(): Doit 2: End Sub
Sub Button3()
Doit Len(ActiveDocument.Paragraphs(1).Range.Text)
End Sub

Sub Doit(lngA As Long)
Dim lngB As Long
For lngB = 1 To lngA
MsgBox "Yes"
Next
End Sub

Sub positionCmdBar()
With ActiveDocument.CommandBars("Formatting")
.Position = msoBarRight
End With
End Sub

' ---------------------------------
Also,
you may use only one button and check,
whether it was clicked together
with [alt] or [ctrl] or [shift],
or combinations of these.

' ---------------------------------

Sub positionCmdBar()
With ActiveDocument.CommandBars("Formatting")
.Position = msoBarRight
End With
End Sub

But, for positioning a commandbar
in autoopen or autonew,
things may be a bit different.
If that applies to you, ask again.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
B

Benjamino5

Helmut,

Thank you for your response!

The way you've done the buttons is actually how I was already doing it--I
just was hoping to simplify it. But that will certainly work.

More importantly, I still have a problem with the commandbar. It's not that
I want it to be docked to the right (msoBarRight), it's that I want it to be
floating AND for the buttons on the commandbar to be laid out vertically.

If you take a standard Word toolbar and drag it to the middle of the screen,
it floats in one long horizontal line. But you can then resize it so that the
commands are stacked. That's how I want my floating toolbars to look--for the
commands to be stacked on top of the other--but still be floating, not docked
on one side of the screen.

Thanks again for your help.
 
H

Helmut Weber

Hi Benjamin,

with the Word version I've got right here and now,
I can't move toolbars with the mouse at all,
whether floating or not.

For your version, maybe,
the height property might help, like:

With ActiveDocument.CommandBars("Formatting")
.Top = 100
.Left = 100
.Height = 1000
' .Width = 1000
End With

I'm at the end of my wisdom with this,
hopefully someone else will know better.

Regards.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
B

Benjamino5

Thanks for all your help. Unfortunately, those suggestions don't result in
what I was hoping for, but I'll just have to leave this question unresolved
for now and move on.
 
C

Cindy M.

Hi Helmut,
with the Word version I've got right here and now,
I can't move toolbars with the mouse at all,
whether floating or not.
Check the Commandbar.Protection property and make sure it's
set to "no protection". You may have been playing with this
once and set protection to not allow moving.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
C

Cindy M.

Hi =?Utf-8?B?QmVuamFtaW5vNQ==?=,
1) I want several CommandBarButtons to call the same subprocedure, but with
different arguments. Yet it seems you can't put arguments in the .OnAction
property--you can only put the name of a sub in there. So how do you make a
button call a sub and also pass it an argument?

I'm guessing the Parameter property might be the answer, but I don't know
how to use it, so a code sample would really help me.
You can use any property, but the Parameter or the Tag properties of the calling
button are the usual ones to use, yes. To get that information in the macro, use
the ActionControl:
Application.CommandBars.ActionControl.Tag 'or Parameter, or Caption
2) When creating a floating palette (commandbar with the property
"msoFloating"), I want the buttons on it to be arranged vertically, one on
top of the next, NOT horizontally. How do I do this? The .Width property of a
commandbar is apparently read-only, so I can't set it.
What I generally do is set the WIDTH of the CommandBar so that it's only just
wide enough for one control.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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