Write to Userform, Textbox properties.

  • I want to create a custom messagebox that will display a list of files that will be written to, and what will be written to them. I want two buttons at the top, proceed and cancel. I'm not sure I'm going about this the right way. I'm imagining a Userform with two textboxes and two buttons. Wading into this venture, I got stuck right away and spent a day on the web trying to figure it out. Please help.


    In vba, I create a Userform from the menu with <Insert> <Userform>. This is the first Userform so it's default name is "Userform1". It's caption name also defaults to "Userform1". I try to change the caption using Userform1.Caption = "New Caption". The code runs, but nothing changes in the Properties panel.


    I add a Textbox to the userform. I want to add some text to the Textbox so I try Userform1.Textbox1.Text = "New Text". I also try "Userform1.Textbox1.Value = "New Text". The code runs, nothing changes in the Properties panel. I thought this would be cake. What am I missing?


    Code
    1. Sub testingUserform()
    2. UserForm1.Caption = "New Caption"
    3. UserForm1.TextBox1.Text = "New Text"
    4. End Sub



    I'm currently running excel from microsoft office 360.

    Edited once, last by royUK: Add Code Tags ().

  • Welcome to Ozgrid. Please take a few minutes to read the Forum Rules to help you get the best out of the Forum. I have added Code Tags for you this time.


    If you change the caption in your code it will change the UserForm caption whilst the UserForm is displayed. It will not change the UserForm's Caption Property andwhen the userForm is closed the Caption will be UserForm1.


    Likewise, the TextBox will only contain the text from the macro until the userform is closed.

  • If you change the caption in your code it will change the UserForm caption whilst the UserForm is displayed. It will not change the UserForm's Caption Property andwhen the userForm is closed the Caption will be UserForm1.


    Likewise, the TextBox will only contain the text from the macro until the userform is closed.

    Thank you royUK, that is the solution. And thanks for the new user tips. I can tag my code here now!


    If someone can help me further, the form I want to create will look like this, listing the files to be written to and the items to be written:

    Can a TextBox output be formatted to look like this?


    FileName1

    Item1, Item2, Item3 ...

    FileName 2

    Item1, Item2 ...

    FileName3

    Item1, Item2, Item3, Item4 ...

    ect...


    Am I going about this the right way; using the Textbox? Can the TextBox.Text property hold a very long string and be formatted to look like the above example? The string will be long enough to need scrollbars and I'll have the "proceed" and "Cancel" buttons at the top of the form.

  • Why not use a ListBox instead?


    If the list is made up of variables you could try this. If the list items are strings then you need to add speech marks - "Item1", etc


    Code
    1. With Me
    2. .textbox1.MultiLine = True
    3. .textbox1.value= filename1 & vbnewline & _
    4. Item1, Item2, Item3 & vbnewline & _
    5. Filename2 & vbnewline & _
    6. Item1, Item2 & vbnewline & _
    7. FileName3 & vbnewline & _
    8. Item1, Item2, Item3, Item4
    9. End With