UserForm TextBox Font Size Problems

Viewed 28

first of all, I hope this question has not been asked befor, I could not find a similar question.

I have a couple of TextBoxes in an UserForm being generated automaticly depending on the amount of rows used in a Excel Sheet. The Text is being pulled from the Cells. That all works without any problems.

Private Sub CreateBoxes()
    Dim lastRow As String
    Dim tb_X As MSForms.TextBox
    Dim TopPos As Integer

    lastRow = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
    
    TopPos = -15
    For i = 1 To lastRow
        If Sheets("Data").Range("C" & i).Value = "Booking" Then
            Set tb_X = Frame6.Controls.Add("Forms.TextBox.1", "tb_" & i, True)
            TopPos = TopPos + 15
            With tb_X
                .Height = 15
                .Width = 190
                .SpecialEffect = fmSpecialEffectFlat
                .Left = 5
                .Top = TopPos
                .Font.Size = 11
                .Text = tB_X.Font.Size  'just a test, to get the set font size
            End With
        End If
    Next
End Sub

The Font.Size is being set to 11. But the text of some of the Textboxes is bigger then from others. If I set the size to 10 or 14 they all are the same, otherwise not. I tried playing with the MultiLine, WordWrap etc. without any success.

Do you have an explanation for this?

PS: I know I could do this with a ListBox, but I want more options for the boxes like different background colors etc. to thats why I decided to use several textboxes rather then one listbox. As far as I know VBA is very limited in this direction.

Thank you!

0 Answers
Related