VBA Text Box: How To Load Different Text
Hello,
I would like to use a VBA Text Box to display different sets of messages that can be invoked from various other VBA sub routines. For example, if someone uses a Pull Down menu to select a User ID, I would llike to use the Pull Down's Sub Routine to assign a message using Text_Box.Text = Range("???##").Text. I don't know if this is the best way to change the contents of a Text Box, but if someone out there more familiar with VBA can help me to understand the correct procedure for accomplishing this, I would be greatful for the insight. -- Regards... |
This is on a userform?
I put a combobox and a textbox on a userform. I used this code: Option Explicit Private Sub ComboBox1_Change() Me.TextBox1.Value = Worksheets("sheet1").Range("a1").Text End Sub Private Sub UserForm_Initialize() Dim iCtr As Long For iCtr = 1 To 10 Me.ComboBox1.AddItem "asdf" & iCtr Next iCtr End Sub ==== You may also want to consider using a label--instead of a textbox. cincode5 wrote: Hello, I would like to use a VBA Text Box to display different sets of messages that can be invoked from various other VBA sub routines. For example, if someone uses a Pull Down menu to select a User ID, I would llike to use the Pull Down's Sub Routine to assign a message using Text_Box.Text = Range("???##").Text. I don't know if this is the best way to change the contents of a Text Box, but if someone out there more familiar with VBA can help me to understand the correct procedure for accomplishing this, I would be greatful for the insight. -- Regards... -- Dave Peterson |
Thanks Dave... You seem to be bailing me out of delimmas more frequently.
I'm slowly coming to understand VBA, and when I wrote this post I was stiffled by what I believe is a sharing issue between Modules and code that resides in worksheet subroutines. The subroutine for the textbox is not in a Module, but will execute the command: Text_Box.Text = Range("A1").Text. But if I write a routine that resides in a Module, this same command results in an Object Qualifier error. Is it possible to goto a subroutine in another worksheet or Module. I think its is, I just dont know enough to figure out how - yet! "Dave Peterson" wrote: This is on a userform? I put a combobox and a textbox on a userform. I used this code: Option Explicit Private Sub ComboBox1_Change() Me.TextBox1.Value = Worksheets("sheet1").Range("a1").Text End Sub Private Sub UserForm_Initialize() Dim iCtr As Long For iCtr = 1 To 10 Me.ComboBox1.AddItem "asdf" & iCtr Next iCtr End Sub ==== You may also want to consider using a label--instead of a textbox. cincode5 wrote: Hello, I would like to use a VBA Text Box to display different sets of messages that can be invoked from various other VBA sub routines. For example, if someone uses a Pull Down menu to select a User ID, I would llike to use the Pull Down's Sub Routine to assign a message using Text_Box.Text = Range("???##").Text. I don't know if this is the best way to change the contents of a Text Box, but if someone out there more familiar with VBA can help me to understand the correct procedure for accomplishing this, I would be greatful for the insight. -- Regards... -- Dave Peterson |
So your textbox is on a worksheet. And you created the textbox using the
control toolbox toolbar? If yes, you can get the value of that textbox by just qualifying where the textbox is: MsgBox Worksheets("sheet1").TextBox1.Value 'or .Text If the textbox is from the Drawing toolbar (but still on a worksheet), you can do: MsgBox Worksheets("sheet1").TextBoxes("text box 2").Text And you can plop the value into the textboxes, too. 'Control toolbox toolbar version Worksheets("sheet1").TextBox1.Text = ActiveSheet.Range("A1").Text 'Drawing toolbar version Worksheets("sheet1").TextBoxes("text box 2").Text _ = ActiveSheet.Range("A1").Text cincode5 wrote: Thanks Dave... You seem to be bailing me out of delimmas more frequently. I'm slowly coming to understand VBA, and when I wrote this post I was stiffled by what I believe is a sharing issue between Modules and code that resides in worksheet subroutines. The subroutine for the textbox is not in a Module, but will execute the command: Text_Box.Text = Range("A1").Text. But if I write a routine that resides in a Module, this same command results in an Object Qualifier error. Is it possible to goto a subroutine in another worksheet or Module. I think its is, I just dont know enough to figure out how - yet! "Dave Peterson" wrote: This is on a userform? I put a combobox and a textbox on a userform. I used this code: Option Explicit Private Sub ComboBox1_Change() Me.TextBox1.Value = Worksheets("sheet1").Range("a1").Text End Sub Private Sub UserForm_Initialize() Dim iCtr As Long For iCtr = 1 To 10 Me.ComboBox1.AddItem "asdf" & iCtr Next iCtr End Sub ==== You may also want to consider using a label--instead of a textbox. cincode5 wrote: Hello, I would like to use a VBA Text Box to display different sets of messages that can be invoked from various other VBA sub routines. For example, if someone uses a Pull Down menu to select a User ID, I would llike to use the Pull Down's Sub Routine to assign a message using Text_Box.Text = Range("???##").Text. I don't know if this is the best way to change the contents of a Text Box, but if someone out there more familiar with VBA can help me to understand the correct procedure for accomplishing this, I would be greatful for the insight. -- Regards... -- Dave Peterson -- Dave Peterson |
All times are GMT +1. The time now is 09:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com