Private Sub CommandButton1_Click()
VerticalLabelTextAlign Label1, aGauche:=True, margin:=True
End Sub
Private Sub CommandButton2_Click()
VerticalLabelTextAlign Label1
End Sub
Private Sub CommandButton3_Click()
VerticalLabelTextAlign Label1, aDroite:=True
End Sub
Function VerticalLabelTextAlign(lab As MSForms.Label, Optional aGauche As Boolean = False, Optional aDroite As Boolean = False, Optional margin As Boolean = False)
Dim chemin, LargeChar&, lblTemp As Object, restelarge, Nb&
chemin = ThisWorkbook.Path & "\centre.jpg"
lab.Caption = Trim(lab.Caption)
With ActiveSheet.ChartObjects.Add(0, 0, 0.05, 0.05).Chart
.Parent.ShapeRange.Line.Visible = msoFalse
.Export chemin, "jpg"
Label1.Picture = LoadPicture(chemin)
.Parent.Delete
End With
If aGauche Then lab.Caption = String(Abs(margin), " ") & Label1.Caption & String(Int(Label1.Width), " ")
If aDroite Then
Set lblTemp = lab.Parent.Controls.Add("Forms.Label.1")
lblTemp.Width = 300
Set lblTemp.Font = lab.Font
lblTemp.Caption = lab.Caption
lblTemp.AutoSize = True
restelarge = lab.Width - lblTemp.Width
lblTemp = "i"
LargeChar = lblTemp.Width
Nb = restelarge / LargeChar
lab.Caption = String(Nb, " ") & Label1.Caption
lab.Parent.Controls.Remove lblTemp.Name
End If
Kill chemin
End Function