Macro bouton activ X

ChantalTreize

XLDnaute Occasionnel
Bonsoir,
Je suis à la recherche d'une macro pour faire un bouton active X pour que je puisse en modifier la couleur
Merci d'avance
Chantal
 

job75

XLDnaute Barbatruc
Bonsoir ChantalTreize,

Si ça peut vous donner des idées :
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, [G5:G8]) Is Nothing Then Exit Sub
Cancel = True
CommandButton1.BackColor = Target.Interior.Color
End Sub
A+
 

Pièces jointes

  • Bouton ActiveX(1).xlsm
    25.7 KB · Affichages: 24

job75

XLDnaute Barbatruc
Re,

Une autre idée :
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If [D4] = "" Then [D4] = "Gris"
CommandButton1.BackColor = Application.VLookup([D4], [{"Orange",49407;"Jaune",65535;"Vert",5296274;"Gris",14277081}], 2, 0)
End Sub
Bonne fin de soirée.
 

Pièces jointes

  • Bouton ActiveX(2).xlsm
    26.1 KB · Affichages: 29

job75

XLDnaute Barbatruc
Bonjour ChantalTreize, le forum,
une macro pour faire un bouton active X
Qu'est-ce à dire ? S'il s'agit de créer un bouton ActiveX pas de problème :
Code:
Private Sub ActiveX_Click()
MsgBox "Bonjour Chantal, le forum !"
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
Set c = [D4] 'à adapter
If Intersect(Target, c) Is Nothing Then Exit Sub
On Error Resume Next
'---suppression du bouton---
If c = "" Then OLEObjects("ActiveX").Delete: Exit Sub
'---création du bouton---
If IsError(OLEObjects("ActiveX")) Then
  With OLEObjects.Add("Forms.CommandButton.1", Width:=0)
    .Name = "ActiveX"
    .Object.Caption = "Message" 'à adapter
    .Object.Font.Bold = True 'gras
    .Object.TakeFocusOnClick = False
    .Top = c(3).Top
    .Left = c.Left + c.Width / 2 - 50
    .Height = 31
    .Width = 100
  End With
End If
'---coloration du bouton---
OLEObjects("ActiveX").Object.BackColor = Application.VLookup(c, [{"Orange",49407;"Jaune",65535;"Vert",10092441;"Gris",14277081}], 2, 0)
End Sub
J'ai éclairci la couleur verte.

Fichier (3).

A+
 

Pièces jointes

  • Bouton ActiveX(3).xlsm
    30.4 KB · Affichages: 29

Discussions similaires

Réponses
3
Affichages
96