COMMAND BAR - need code to put sheet names in customs CBs as

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,778
I am using the following code to put worksheet names in controls that are made from a MenuMaker sheet. I had to start using 2 commandbars because I could not find a way to wrap the CBs.

Problem - how to get sheet names to go to the applicable custom CB controls. Line 13 is where I am running into problems ...<pre>Option Explicit

Dim CB As CommandBar
Dim WS As Worksheet
Dim MenuSheet As Worksheet
Dim MenuObject As CommandBarPopup
Dim MenuItem As Object 'used in case 2 and 3 for items under menu
Dim SubMenuItem As CommandBarButton
Dim WSNum As Integer
Dim strName As String
Dim strActionName As String

Sub WS_Get_Listings(cntrl As String, prefix As String)

On Error Resume Next
Set MenuObject = Application.CommandBars("??????").Controls(cntrl)

'Delete existing Worksheet names but not hard coded buttons
For Each MenuItem In MenuObject.CommandBar.Controls
For Each WS In Worksheets
If Left(WS.Name, Len(prefix)) Like prefix Then
' Remove the sheet prefix
strName = Right(WS.Name, Len(WS.Name) - Len(prefix))
If strName = MenuItem.Caption Then MenuItem.Delete
End If
Next
Next

strActionName = ThisWorkbook.Name & "!GoTo_ListingsSheets"
'adds all worksheets meeting criteria
WSNum = 0
For Each WS In Worksheets
If Left(WS.Name, Len(prefix)) Like prefix Then
'Remove the prefix
strName = Right(WS.Name, Len(WS.Name) - Len(prefix))
WSNum = WSNum + 1 ' this ensures WS are at top of control in the order _
they appear in workbook AND puts hard coded controls at _
bottom of control. Divider is used to seperate the two ...
MenuObject.Controls.Add(Before:=WSNum).Caption = strName
MenuObject.Controls(strName).OnAction = strActionName
MenuObject.Controls(strName).DescriptionText = WS.Name
End If
Next
On Error GoTo 0

End Sub

Sub WS_Get_FIL()
WS_Get_Listings cntrl:="File Maint", prefix:="fil-"
End Sub
Sub WS_Get_SAF()
WS_Get_Listings cntrl:="Safety", prefix:="saf-#"
End Sub</pre>
TestmenuMaker.xls
ABCDEFGHIJ
2CommandBarSetupCBsShown
3MenuLevelNameCaptionPositionMacroDividerFaceIDFutureuseFutureuseFutureuse
4CommandBarTest1
5MenuFileMaintWS_Get_FIL
6MenuItemShowToolbarsCB_ShowAllTRUE
7ComBarButtonIntroSheetGoToIntroTRUE
8MenuSafetyWS_Get_SAFTRUE
9MenuInspectionInfoWS_Get_INPTRUE
10MenuItemtest45TRUE
11MenuMiscWS_Get_MISTRUE
12CommandBarTest22
13MenuSafetyWS_Get_SAFTRUE
14MenuInspectionInfoWS_Get_INPTRUE
15
fil-Menu Maker-2

This message was edited by em on 2002-11-06 08:58
This message was edited by em on 2003-02-09 17:25
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,143,613
Messages
5,719,708
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