Consulting

Results 1 to 6 of 6

Thread: How to rename TextBoxes on userform

  1. #1

    How to rename TextBoxes on userform

    Dear All,

    I have created 112 TextBox on userform.
    Please advise how to rename these of them by macro.

    -TextBox21 - TextBox43 ==> aTextBox21 - aTextBox43
    -TextBox44 - TextBox66 ==> bTextBox21 - bTextBox43
    -TextBox67 - TextBox89 ==> cTextBox21 - cTextBox43
    -TextBox90 - TextBox112 ==> dTextBox21 - dTextBox43

  2. #2
    VBAX Regular
    Joined
    Apr 2016
    Posts
    35
    Location
    You can change them name with array easly. Set New names and old names after you can loop them easly.

    Dim oldNames As Variant, newNames As Variant, i As Long
    oldNames = Array("TextBox21", "TextBox43", "TextBox44")
    newNames = Array("aTextBox21", "aTextBox43", "bTextBox21")

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    You can't rename controls at runtime (i.e. via macro)

    It might be possible to automate the process by exporting the UserForm (which gives you a FRM and FRX file), then use a macro to process the FRX binary file replacing strings, and then import the file to the project

    The file in binary looks like this

    Capture.jpg

    Seems lot a lot of work
    Last edited by Paul_Hossler; 11-30-2018 at 05:01 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    .
    Wonder if a redesign is in order for the user form ? 112 textboxes on one form seems like a lot.

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by Logit View Post
    .
    Wonder if a redesign is in order for the user form ? 112 textboxes on one form seems like a lot.
    Especially if they weren't giving meaningful names at design time, e.g. tbStartDate instead of TextBox87
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I think this will do the job.

    Sub test()
        Dim i As Long
       
        With ThisWorkbook.VBProject.VBComponents("Userform1").Designer
            For i = 21 To 43
                .Controls("TextBox" & i).Name = "a" & "TextBox" & i
                .Controls("TextBox" & (i + 23)).Name = "b" & "TextBox" & i
                .Controls("TextBox" & (i + 46)).Name = "c" & "TextBox" & i
                .Controls("TextBox" & (i + 69)).Name = "d" & "TextBox" & i
            Next i
        End With
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •