Modifier text et couleur de Shape

Bonjour chers tous

Jai une macro associée à une Shape qui doit afficher ou masquer une feuille .

La chape doit changer de couleur et de texte si la feuille est affichée sinon reprendre l'état initial .

Jai nommé la Shape : pn

Option Explicit
Dim shp As Shape
Dim couleur As ColorFormat
Dim n As String
Sub aff()
Set shp = ActiveSheet.Shapes(pn)
couleur = shp.Fill.ForeColor.RGB
n = shp.TextFrame.Characters.Text
If n = "AFFICHER" Then
        Application.ScreenUpdating = False
        Sheets("Travail").Visible = True
        shp.TextFrame.Characters.Text = "MASQUER"
        shp.Fill.ForeColor.RGB = RGB(238, 93, 93)
Else
        Application.ScreenUpdating = False
        Sheets("Travail").Visible = False
        shp.TextFrame.Characters.Text = "AFFICHER"
        shp.Fill.ForeColor.RGB = couleur
End If
End Sub
6shap.xlsm (15.32 Ko)

Bonjour,

Option Explicit

Sub Aff()

Dim shp As Shape

    Set shp = Sheets("Feuil1").Shapes("pn")
    Application.ScreenUpdating = False

    With shp

         If .TextFrame.Characters.Text = "AFFICHER" Then
            Sheets("Travail").Visible = True
            .TextFrame.Characters.Text = "MASQUER"
            .Fill.ForeColor.RGB = RGB(238, 93, 93)
        Else
            Sheets("Travail").Visible = False
            .TextFrame.Characters.Text = "AFFICHER"
            .Fill.ForeColor.RGB = RGB(68, 114, 196)
        End If

    End With

    Set shp = Nothing
    Application.ScreenUpdating = True

End Sub
Rechercher des sujets similaires à "modifier text couleur shape"