- ' dans le thisworbook :
- ' lors du click_droit dans une cellule, si elle contient le mot "coucou"
-
- Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal target As Range, Cancel As Boolean)
- If InStr(1, target.formulalocal, "coucou") > 0 Then
- Sh.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
- , DisplayAsIcon:=False, Left:=target.Left, Top:=target.Top + target.Height, _
- Width:=target.Width, Height:=target.Height * 2).Name = "temp"
- Addcommand target.AddressLocal
- Cancel = True
- End If
- End If
- End Sub
- Sub Addcommand (ByVal ref As String)
- Dim tmpbutton As OLEObject
- Set Gbutton = New class_bulle
- Gbutton.rge = ref
- Set Gbutton.Buttn = ActiveSheet.OLEObjects("temp").Object
- End Sub
- '---------------------------------------------------------------------------------------------
- ' Dans un module de classe : (class_bulle)
- '---------------------------------------------------------------------------------------------
- Private WithEvents Butt As MSForms.CommandButton
- Private addres As String
-
- Property Set Buttn(oButton As MSForms.CommandButton)
- Set Butt = oButton
- Butt.Caption = "Insérer la Valeur par Defaut.."
- Butt.BackColor = 10079487
- End Property
-
- Property Get Buttn() As MSForms.CommandButton
- Set Buttn = Butt
- End Property
-
- Public Property Let rge(rg As String)
- addres = rg
- End Property
-
- Public Property Get rge() As String
- rge = addres
- End Property
-
- Private Sub Butt_Click()
- MsgBox "add : " & addres
- ActiveSheet.Shapes("temp").delete
- End Sub
' dans le thisworbook :
' lors du click_droit dans une cellule, si elle contient le mot "coucou"
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal target As Range, Cancel As Boolean)
If InStr(1, target.formulalocal, "coucou") > 0 Then
Sh.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=target.Left, Top:=target.Top + target.Height, _
Width:=target.Width, Height:=target.Height * 2).Name = "temp"
Addcommand target.AddressLocal
Cancel = True
End If
End If
End Sub
Sub Addcommand (ByVal ref As String)
Dim tmpbutton As OLEObject
Set Gbutton = New class_bulle
Gbutton.rge = ref
Set Gbutton.Buttn = ActiveSheet.OLEObjects("temp").Object
End Sub
'---------------------------------------------------------------------------------------------
' Dans un module de classe : (class_bulle)
'---------------------------------------------------------------------------------------------
Private WithEvents Butt As MSForms.CommandButton
Private addres As String
Property Set Buttn(oButton As MSForms.CommandButton)
Set Butt = oButton
Butt.Caption = "Insérer la Valeur par Defaut.."
Butt.BackColor = 10079487
End Property
Property Get Buttn() As MSForms.CommandButton
Set Buttn = Butt
End Property
Public Property Let rge(rg As String)
addres = rg
End Property
Public Property Get rge() As String
rge = addres
End Property
Private Sub Butt_Click()
MsgBox "add : " & addres
ActiveSheet.Shapes("temp").delete
End Sub