Announcement

Collapse
No announcement yet.

Unconfigured Ad Widget

Collapse

Vertically Center Text In Userform Label

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Vertically Center Text In Userform Label

    Is it possible to vertically center the text in a userform label?

    For example: I have a label that's 22px high, but the text is only 10pt -- at the moment it just hangs out at the top of label looking bad.... I'd like to place it the middle if possible.

    thanks,
    eric

  • #2
    Re: Vertically Center Text In Userform Label

    The label control has no built in vertical alignment.
    The simplest way is to use 2 labels. One displays the border at the required size.
    The other is autosize to fit display text and then centered over the other label.

    This code assume 2 labels on a userform
    Label1 formatted to size of holding border.
    Label2 to hold text and center both vertically and horizontally.


    With Label2
    .AutoSize = False
    .Height = 100
    .Width = 200
    .Caption = "This is my" & vbLf & "label text"
    .AutoSize = True
    .Top = Label1.Top + ((Label1.Height - .Height) / 2)
    .Left = Label1.Left + ((Label1.Width - .Width) / 2)
    End With

    Cheers
    Andy

    Comment


    • #3
      Re: Vertically Center Text In Userform Label

      ah yes..... very sneaky! thanks andy!

      Comment

      Trending

      Collapse

      There are no results that meet this criteria.

      Working...
      X