COMMANDBAR - CB ends up under Window Menu Bar ??

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,778
How do I ensure a custom command bar ends up under the Window Men Bar when opening, deactivating and activating the workbook.

I think I am running all the code correctly but I can't seem to get the right combination of index, rowindex, position, top or something correct.

I also have code that hides and unhides existing visible command bars.

Sometimes the custom bar is on top of the WMB, or it is the forth bar down (standard and formatting ends up between custom and WMB).

IN THE CREATE BAR SUB I'M USING THIS:<pre>Set UDMcb = CommandBars.Add
With UDMcb
.Name = "UDM"
.Enabled = True
.Visible = True
.Position = msoBarTop
'.RowIndex = msoBarRowLast
.Top = 1
.Left = 0
.Visible = True
.Protection = msoBarNoCustomize + msoBarNoMove
End With</pre>


IN THE WORKBOOK ACTIVATE SUB I'M TRYING SOMETHING LIKE THIS:<pre>Private Sub Workbook_Activate()
On Error Resume Next
' make the commandbar visible when the workbook is activated
Application.CommandBars("UDM").Visible = True
Application.CommandBars("UDM").Position = 1
On Error GoTo 0
End Sub</pre>
This message was edited by EM on 2002-10-15 01:51
This message was edited by em on 2002-10-18 01:24
This message was edited by em on 2002-10-18 01:26
This message was edited by em on 2003-01-31 23:51
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Mala

MrExcel MVP
Joined
Apr 4, 2002
Messages
627
Try the following code to create the command bar and dock it below the menu bar:

Set UDMcb = CommandBars.Add
With UDMcb
'.Controls.Add (1)
.Name = "UDM"
.Enabled = True
.Visible = True
.Position = msoBarTop
.RowIndex = CommandBars(1).RowIndex + 1
.Visible = True
.Protection = msoBarNoCustomize + msoBarNoMove
End With
The commandbar will be docked in a new row below the menu bar.

Use this code to control visibility from the ThisWorkbook module:

Private Sub Workbook_Activate()
On Error Resume Next
' make the commandbar visible when the workbook is activated
Application.CommandBars("UDM").Visible = True
On Error GoTo 0
End Sub

Private Sub Workbook_Deactivate()
On Error Resume Next
' make the commandbar invisible when the workbook is deactivated
Application.CommandBars("UDM").Visible = False
On Error GoTo 0
End Sub
 

Forum statistics

Threads
1,143,614
Messages
5,719,720
Members
422,242
Latest member
hishamkhatri

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
Top