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
    Sub testingUserform()
    UserForm1.Caption = "New Caption"
    UserForm1.TextBox1.Text = "New Text"
    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
    With Me
    .textbox1.MultiLine = True
    .textbox1.value= filename1 & vbnewline & _
    Item1, Item2, Item3  & vbnewline & _
    Filename2 & vbnewline & _
    Item1, Item2 & vbnewline & _
    FileName3 & vbnewline & _
    Item1, Item2, Item3, Item4
    End With

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!