COMMANDBAR - CB ends up under Window Menu Bar ??

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,786
Office Version
  1. 2016
Platform
  1. Windows
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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
 
Upvote 0
Mala -- thanks, I wll give it a shot toight ...
 
Upvote 0

Forum statistics

Threads
1,222,045
Messages
6,163,583
Members
451,846
Latest member
ajk99

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