Menus

brettvba

MrExcel MVP
Joined
Feb 18, 2002
Messages
1,030
I have created a custom menu in an addin how do I get the menu to automatically attach itself to the toolbar instead of just floating?

Brett

EDIT:

Also does anyone know how to make the file install to the addin directory so that the addin opens with excel
This message was edited by brettvba on 2003-02-12 22:30
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Brett.
To dock your bar use the Position property of the commandbar class.

Ex.

Set cBar = Application.CommandBars("YourBar")
cBar.Position = msoBarTop

If you want your bar up top you may be better off adding custom controls to an existing commandbar such as the Worksheet Menu Bar. Most addins exhibit their functionality in this way.

As far as the installation? I would assume that the Office Developers Addition includes distibution software or you could use third party installers. It would be possible to create your own using a standalone workbook as well. I use VB to install the addin. If you have VB then create a simple GUI and place the xla in a resource file. This gives you the abiltity to install with a single file if you are installing on Windows 98/NT 4 or later. The installer I created only installs for the current user. I have seen free installers on the web though I cannot recall where.

Tom
 
Upvote 0
Thanks Tom,

All I was wanting to do was basically add a button to the toolbar I just can't remember how I did this last time?

Brett
 
Upvote 0
Maybe a quick study of this code will help you. Run it to see how it works...<pre>

Sub AddControls()

Dim cBarParentBar As CommandBar
Dim cBarParentBarPopUp As CommandBarPopup
Dim cBarParentBarPopUpControls(1 To 5) As CommandBarButton
Dim intArrayCounter As Integer

Set cBarParentBar = Application.CommandBars( _
"Worksheet Menu Bar")

On Error Resume Next
cBarParentBar.Controls("Popup Control").Delete
On Error GoTo 0

Set cBarParentBarPopUp = cBarParentBar.Controls.Add( _
msoControlPopup, , , , True)

With cBarParentBarPopUp
.Caption = "Popup Control"
.Visible = True
End With

For intArrayCounter = 1 To 5
Set cBarParentBarPopUpControls(intArrayCounter) = cBarParentBarPopUp.Controls.Add( _
msoControlButton, , , , True)

With cBarParentBarPopUpControls(intArrayCounter)
.Caption = "Add button # " & intArrayCounter
.Style = msoButtonCaption
.Visible = True
.OnAction = "CommandBarButton_Click"
.Tag = intArrayCounter
End With
Next

Erase cBarParentBarPopUpControls
Set cBarParentBarPopUp = Nothing
Set cBarParentBar = Nothing

End Sub


Sub CommandBarButton_Click()

Select Case Application.CommandBars.ActionControl.Tag
Case 1
MsgBox "Run code for button 1"
Case 2
MsgBox "Run code for button 2"
Case 3
MsgBox "Run code for button 3"
Case 4
MsgBox "Run code for button 4"
Case 5
MsgBox "Run code for button 5"
End Select

End Sub</pre>

Tom
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top