requirement for creating a sub menu in c# excel addin

S

shantanu

Dear All
I have a requirement for creating a sub menu. I have been
working on the addin and was able to put the addin in the tools menu
of excel. The menu will be something like:

1. Main Item
1.a. Sub item 1
1.a.i sub item 1
1.a.ii sub item 2
1.b. Sub item 1
1.b.i sub item 1
1.b.ii sub item 2

Can anybody help in creating this kind of menu formation in excel from
C# addin.

Regards
shantanu
 
B

Bob Phillips

Here is an example

Sub MultiLevelMenus()
Dim oCb As CommandBar
Dim oCtl1 As CommandBarPopup
Dim oCtl2 As CommandBarPopup
Dim oCtl3 As CommandBarPopup
Dim oCtlBtn As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl1 = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl1.Caption = "Level1"
With oCtl1
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level1 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel1Button1Macro"
With oCtl1
Set oCtl2 = .Controls.Add( _
Type:=msoControlPopup)
oCtl2.Caption = "Level2"
With oCtl2
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level2 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel2Button1Macro"
Set oCtl3 = .Controls.Add( _
Type:=msoControlPopup)
oCtl3.Caption = "Level3"
With oCtl3
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level3 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel3Button1Macro"
End With
End With
End With
'etc.
End With
End With
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
S

shantanu

Here is an example

Sub MultiLevelMenus()
Dim oCb As CommandBar
Dim oCtl1 As CommandBarPopup
Dim oCtl2 As CommandBarPopup
Dim oCtl3 As CommandBarPopup
Dim oCtlBtn As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl1 = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl1.Caption = "Level1"
With oCtl1
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level1 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel1Button1Macro"
With oCtl1
Set oCtl2 = .Controls.Add( _
Type:=msoControlPopup)
oCtl2.Caption = "Level2"
With oCtl2
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level2 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel2Button1Macro"
Set oCtl3 = .Controls.Add( _
Type:=msoControlPopup)
oCtl3.Caption = "Level3"
With oCtl3
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level3 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel3Button1Macro"
End With
End With
End With
'etc.
End With
End With
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)









- Show quoted text -

thanx for the code but can u get me in C# as i am not familiar with vb
reagrds
shantanu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top