'******************************************
'sujet: centrer verticalement le texte de la caption d'un label dans un userform
'       a l'aide d'un bouton dans une commandbarre temporaire et dynamique
'date:10/11/2021
'auteur: patricktoulon sur exceldownloads
'version:2.1 (2021) sans créeation de commandbars mais en utilisant la commandbars (1)
''******************************************
Private Sub CommandButton1_Click()
   Call centrer_le_text(Label1)
End Sub
Sub centrer_le_text(obj As msforms.Label)
    Dim bout As CommandBarControl, shap As Shape
    Set bout = CommandBars(1).Controls.Add(Type:=msoControlButton)
    Set shap = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 0, 0, 1, 1)
    With shap: .Line.Visible = msoFalse: .Fill.Visible = msoFalse: .CopyPicture: .Delete: End With 'copypicture=copie en WMF(garde la transparence)
    bout.PasteFace
    With obj
        .Picture = bout.Picture
        .PicturePosition = fmPicturePositionCenter
        .TextAlign = 2
    End With
    CommandBars(1).Reset
End Sub