How can I edit the code in this KB entry to make a floating menu bar, instead of one that sits on the default menu bar?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=14
How can I edit the code in this KB entry to make a floating menu bar, instead of one that sits on the default menu bar?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=14
~Anne Troy
I did try:
[vba]CommandBars("St&andards").Position = msoBarFloating[/vba]
But it didn't change anything when I closed and reopened the doc.
~Anne Troy
A workaround.
Add the following at the end of the DocumentOpen sub
[VBA]
CommandBars.Add(Name:="MyMacros").Visible = True
CommandBars("Menu Bar").Controls(11).Copy Bar:=CommandBars("MyMacros")
[/VBA]
BTW, The signature macros would not run in 2000 until the extraneous spaces were deleted.
eg
from
A(1) = Array("Suat's Signature " , " Ozgur " , 92)
to
A(1) = Array("Suat's Signature", "Ozgur", 92)
Were the spaces deliberate, or created by the KB?
MD
I don't know, but I'm not using those anyway...
~Anne Troy
Hi DB,
This should do the trick. I knew nothing about toolbar manipulation before, so well worth the effort! Replace the Document Open macro as follows:
[VBA]
Private Sub Document_Open()
'The Dim statements make the rest of the code easier to create.
Dim Mybar As CommandBar
Dim cmd As CommandBarPopup
Dim i As Integer
Dim A(12) As Variant
Dim Check
CustomizationContext = ActiveDocument.AttachedTemplate
On Error Resume Next
'This checks if the menu already exists. If it does, it does not create a new one.
Check = CommandBars("MyMacros").Position
Set Mybar = CommandBars.Add(Name:="MyMacros", _
Position:=msoBarFloating, Temporary:=True)
If Not Err.Number = 0 Then
'Note that the parts of the array are ( " Title of menu option " , " Macro to Run " , FaceID for toolbar button)
A(1) = Array("Suat's Signature", "Ozgur", 92)
A(2) = Array("Anne's Signature", "Smith", 85)
A(3) = Array("Nancy's Signature", "Johnson", 89)
A(4) = Array("Dreamboat's Signature", "Dreamboat", 80)
A(5) = Array("Mickey's Signature", "Mouse", 98)
A(6) = Array("Insert Photo", "InsPic", 280)
A(7) = Array("Fix Picture", "FixPix", 1363)
A(8) = Array("Add Photo Heading", "PhotoCont", 314)
A(9) = Array("Insert Stopping Point", "StopPoint", 2528)
A(10) = Array("Find Last Stopping Point", "StartHere", 2526)
A(11) = Array("Print Just This Page", "PrtPg", 159)
A(12) = Array("Insert Landscape Page", "InsertLand", 6)
Mybar.Visible = True
Set Mytasks = Mybar.Controls.Add(Type:=msoControlPopup)
Mytasks.Caption = "Te&mplates"
'The ampersand (&) in the name of the menu underlines the letter that follows it to give
'it a keyboard command (Alt-m) as many menus have.
With CommandBars("MyMacros").Controls("Te&mplates").Controls
For i = 1 To UBound(A)
Set myButton = .Add(Type:=msoControlButton)
With myButton
.Caption = A(i)(0)
.OnAction = A(i)(1)
.FaceId = A(i)(2)
End With
Next i
End With
Else
End If
End Sub
[/VBA]
and change Document Close to
[VBA]Private Sub Document_Close()
'This closes the MyMacros toolbar when the document is closed. It also keeps the user from
'changing the template. This is what we call an *on-event* procedure (macro) because it is
'run when the document is closed.
On Error Resume Next
CommandBars("MyMacros").Delete
ActiveDocument.AttachedTemplate.Saved = True
End Sub
[/VBA]
Thank you, sweetie! Tho I prolly won't get to check it until late, late tonight or tomorrow.
But I will letcha know!
~Anne Troy
Unacceptable!! Check it now!!Originally Posted by Dreamboat
My email read:
Here is the message that has just been posted:
Unacceptable!! Check it now!! ;Whip
I thought it was a comment on my coding!!!!
I was going to post some code but when I came back MD had already done it, so all I have to say is that the code doesn't run with Option Explicit - it needs (at least) a declaration of myButton. Should we change it in the KB?
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
No. Let's leave it wrong.
ROFL!!
Don't worry. I'll fix it tomorrow. I do recall having problems...
~Anne Troy
Yeah, all variables should be declared and Option Explicit used in all code.
Very nice code mdmackillop! I have wondered if it would be possible to bring together bits and pieces of various toolbars I've cadged together from assorted projects over the years. Seeing this gives me hope.
So how should the Mytasks and myButton variables be defined? I wasn't sure what data type to use (Dim myButton As ???). It does work without specifying a data type and I assume (by process of elimination mainly) that it would be either Variant or Object. Is there any advantage to using an explicit data type?
Eric
Experience is not what happens to a man; it is what a man does with what happens to him. ? Aldous Huxley
Hi Eric,
All credit goes to Smozgur (see link in fist thread).
Re the variable, I would go along with defining them, with the correct values if known, but I'm a bit unclear on some of these also. Trial and error!
MD
Hi Eric,
It's almost always better to use explicit data types.
In this case myButton could be CommandBarControl or, better, CommandBarButton (the Type:=msoControlButton is a bit of a giveaway).
If you don't know what type to use for an object, you can use the TypeName Function after it's been set, for example
[VBA]Dim myObject
Set myObject = CommandBars(1).Controls(1)
Msgbox TypeName(myObject)[/VBA]
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Don't forget about the popup ...
CommandBarPopup
Regards, Zack Barresse
Check out the KB! :|: BOARD TAGS: WHAT ARE THEY AND HOW DO I USE THEM
What is a Microsoft MVP? | Free Microsoft Courses | My Book on Excel Tables
Okay. I'll be working on the menu this weekend. May need some other code help too. If anybody is going to be around and wants to make a few sheckles... it'd be nice to know who's willin'.
~Anne Troy
I've added Option Explicit and split off the button naming to another sub to give some menu options on the toolbar.
Well, if there's sheckels in it ....
Seriously, I'll be around
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Cool.
~Anne Troy