none
How to define Width and Height for each TextBox in one Frame of a UserForm RRS feed

  • Question

  • Hello,

    I have a lot of TextBoxes grouped in two Frames in my UserForm.

    I need to specify the same Height and the same Width for every TextBox.

    How can I do that with a VBA proc?

    Thanks

    Thursday, December 8, 2016 9:50 AM

Answers

  • Hi,

    does the following work for you?

    Private Sub UserForm_Initialize()
    Dim I As Integer
    Dim J As Integer
    
    For I = 0 To MyForm.Controls.Count - 1
        If TypeOf MyForm.Controls(I) Is Frame Then
            For J = 0 To MyForm.Controls(I).Controls.Count - 1
                'MsgBox MyForm.Controls(i).Controls(j).Name
                If TypeOf MyForm.Controls(I).Controls(J) Is TextBox Then
                    MsgBox "Old values " & MyForm.Controls(I).Controls(J).Height & ", " & MyForm.Controls(I).Controls(J).Width
                    MyForm.Controls(I).Controls(J).Height = 20
                    MyForm.Controls(I).Controls(J).Width = 20
                End If
            Next J
        End If
    Next I
    End Sub

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!


    Thursday, December 8, 2016 10:53 AM
    Moderator
  • Hi,

    sorry, "MyForm" is just the name of my form .... So you need to replace MyForm by your form name.

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Thursday, December 8, 2016 1:26 PM
    Thursday, December 8, 2016 11:26 AM
    Moderator

All replies

  • Hi,

    does the following work for you?

    Private Sub UserForm_Initialize()
    Dim I As Integer
    Dim J As Integer
    
    For I = 0 To MyForm.Controls.Count - 1
        If TypeOf MyForm.Controls(I) Is Frame Then
            For J = 0 To MyForm.Controls(I).Controls.Count - 1
                'MsgBox MyForm.Controls(i).Controls(j).Name
                If TypeOf MyForm.Controls(I).Controls(J) Is TextBox Then
                    MsgBox "Old values " & MyForm.Controls(I).Controls(J).Height & ", " & MyForm.Controls(I).Controls(J).Width
                    MyForm.Controls(I).Controls(J).Height = 20
                    MyForm.Controls(I).Controls(J).Width = 20
                End If
            Next J
        End If
    Next I
    End Sub

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!


    Thursday, December 8, 2016 10:53 AM
    Moderator
  • Great! Very interesting !

    But how do you define MyForm?

    Thanks a lot

    Thursday, December 8, 2016 11:18 AM
  • Hi,

    sorry, "MyForm" is just the name of my form .... So you need to replace MyForm by your form name.

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Thursday, December 8, 2016 1:26 PM
    Thursday, December 8, 2016 11:26 AM
    Moderator
  • That works fine!

    Thanks a lot Barbara

    Thursday, December 8, 2016 1:27 PM