1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Option Explicit
Global cb_Menu As CommandBar
Global WSObj As Collection
Global ws As Worksheet
Sub SetupAllWSEvents()
Dim WSo As ClsWS
Set WSObj = Nothing
Set WSObj = New Collection
For Each ws In ActiveWorkbook.Worksheets
Set WSo = New ClsWS
Set WSo.WSToMonitor = ws
WSObj.Add WSo, ws.Name
Next ws
End Sub
Function CreateMyOwnSubMenu() As CommandBar
Dim menubar As CommandBar
Dim menuItem As CommandBarControl
Dim subMenuItem As CommandBarControl
'remove previous instance
Call DeleteCommandBar("myOwnSubMenu")
'Add our popup menu to the CommandBars collection
Set menubar = CommandBars.Add(Name:="myOwnSubMenu", _
Position:=msoBarPopup, _
menubar:=False, _
Temporary:=False)
Set menuItem = menubar.Controls.Add(Type:=msoControlPopup)
Call AddMenu(menuItem, "Séjour", "Séjour1")
Set CreateMyOwnSubMenu = menubar
Set menubar = Nothing
End Function
Sub AddMenu(newMenu As CommandBarControl, titre As String, reference As String)
With newMenu
.Caption = "&" & titre
.OnAction = "'" + "goToCelluleX " + """" + reference + """" + "'"
End With
End Sub
Sub goToCelluleX(xStr As String)
Dim objWorksheet As Excel.Worksheet
Set objWorksheet = ThisWorkbook.Sheets("EtatdesLieux")
objWorksheet.Range(xStr).Activate
End Sub |
Partager