I just tried the approach outlined in the top voted answer and it worked perfectly. To add a little to the approach though - if you have many labels for example, I did the following:
- Add a picture control somewhere on the userform (anywhere doesn't matter). Change the control's properties to the following:
Property |
Value |
Name |
GIF |
Picture |
(set to be the 1x1 transparent gif picture [link]) |
Visible |
False |
- Now for each of the Label controls which you want to receive the special alignment change the tag property:
Property |
Value |
Tag |
"LabelAlignmentTheme" |
- Finally add the following code to
UserForm_Initialize
Private Sub UserForm_Initialize()
'Apply the fix in https://mcmap.net/q/569419/-how-do-i-vertically-center-the-text-in-an-excel-label-39-s-caption
'To all labels with the matching Tag
Dim ctrl As MSForms.control
For Each ctrl In Me.controls
If TypeOf ctrl Is MSForms.label And ctrl.Tag = "LabelAlignmentTheme" Then
Dim label As MSForms.label
Set label = ctrl
Set label.Picture = Me.GIF.Picture 'read the picture from the picture control
label.PicturePosition = fmPicturePositionLeftCenter
End If
Next
End Sub
I like this use of Tag
, it feels like a css style. Obviously you can skip the check for the tag (remove the second half of the And statement) and align absolutely everything but I think this is a more realistic scenario where you only want some aligned.
By storing the image in a shared hidden picture somewhere in the form, it is embedded in the file.