Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to refer to the .text property without text box name?
I have a textbox called txtNew.
How can i use the .text property without actually typing txtNew.text? I dont want to use "with" statement. is there any way to refer like "this.text"? (so that i can use those statements for all the textboxes, if necessary) Sub txtNew_Change ....some statement this.text ....some statement End sub sub txtNew1_Change ....some statement this.text ....some statement End sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to refer to the .text property without text box name?
From inside an event procedure for any control, you could refer to that
control via the ActiveControl object (since, in order for the event procedure of a control to be running, that control must be the active control). So, for your example Change event for, say, txtNew1... Sub txtNew1_Change() ....some statement ActiveControl.Text ....some statement End sub Although, if you are in an event procedure, it must be for a particular control which you know the name of, so using an indirection through the ActiveControl doesn't really gain anything over just using the control name itself within its own event procedure. The real benefit of ActiveControl would be in a common Sub or Function called from several similar controls' event procedure so that the Sub or Function could figure out which control it was executing its code for. So, in the two code samples you posted, if all the "some statements" were identical, except for the control they were being executed for, putting those statements in a Sub, and having each of those Change event procedures call that Sub (which in turn used the ActiveControl to figure out which control's Change event called it), would be a more logical use of ActiveControl. Rick "Yajiv" wrote in message ... I have a textbox called txtNew. How can i use the .text property without actually typing txtNew.text? I dont want to use "with" statement. is there any way to refer like "this.text"? (so that i can use those statements for all the textboxes, if necessary) Sub txtNew_Change ...some statement this.text ...some statement End sub sub txtNew1_Change ...some statement this.text ...some statement End sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
refer a cell text in b1 and extract remaing text from a1 | Excel Discussion (Misc queries) | |||
refer to text | Excel Discussion (Misc queries) | |||
How can I refer to a worksheet using text in a cell? | Excel Discussion (Misc queries) | |||
Excel VBA: Worksheet cell .Text property: 1024 bytes text len limit | Excel Programming | |||
How do i refer to the text typed in a combobox? | Excel Programming |