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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Option Compare Database
Option Explicit
Const sNomMenuContextuel As String = "menu contextuel marcb03"
Public Sub CréerMenuContextuelTemporaire()
Dim oBar As Office.CommandBar
Dim vCmds As Variant, v As Variant, bBeginGroup As Boolean
' On se protège !
' Si le menu contextuel existe déjà, on le supprime.
On Error Resume Next
Application.CommandBars(sNomMenuContextuel).Delete
On Error GoTo 0
Set oBar = Application.CommandBars.Add(sNomMenuContextuel, msoBarPopup, , True)
' Liste des commandes du menu
vCmds = Array("Zoom ajusté", "Zoom à 10 %", "Zoom à 25 %", "Zoom à 50 %", _
"Zoom à 75 %", "Zoom à 100 %", "Zoom à 150 %", "Zoom à 200 %", _
"|", "Imprimer", _
"|", "Exporter dans Word", "Exporter dans Excel", _
"|", "Fermer")
For Each v In vCmds
If v = "|" Then
' annoncer un début de groupe (trait de séparation)
bBeginGroup = True
Else
' ajouter un contrôle
With oBar.Controls.Add(msoControlButton, 1)
.BeginGroup = bBeginGroup
.Caption = v
.OnAction = "ActionMenuContextuel"
End With
bBeginGroup = False
End If
Next v
End Sub
Public Sub ActionMenuContextuel()
Dim oCtrl As Office.CommandBarControl
On Error GoTo ExitSub
Set oCtrl = Application.CommandBars.ActionControl
If oCtrl.Parent.Name = sNomMenuContextuel Then
Select Case oCtrl.Index
Case 1: DoCmd.RunCommand acCmdFitToWindow
Case 2: DoCmd.RunCommand acCmdZoom10
Case 3: DoCmd.RunCommand acCmdZoom25
Case 4: DoCmd.RunCommand acCmdZoom50
Case 5: DoCmd.RunCommand acCmdZoom75
Case 6: DoCmd.RunCommand acCmdZoom100
Case 7: DoCmd.RunCommand acCmdZoom150
Case 8: DoCmd.RunCommand acCmdZoom200
Case 9: DoCmd.RunCommand acCmdPrint
Case 10
DoCmd.OutputTo acReport, Screen.ActiveReport.Name, acFormatRTF, , True
Case 11
DoCmd.OutputTo acReport, Screen.ActiveReport.Name, acFormatXLS, , True
Case 12
DoCmd.Close acReport, Screen.ActiveReport.Name, acSaveYes
End Select
End If
ExitSub:
' fini !
End Sub |
Partager