Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
refer a cell text in b1 and extract remaing text from a1 Narnimar Excel Discussion (Misc queries) 4 April 3rd 10 12:30 PM
refer to text Lowan Chan Excel Discussion (Misc queries) 9 October 20th 09 05:46 AM
How can I refer to a worksheet using text in a cell? Preston Excel Discussion (Misc queries) 3 October 13th 06 01:35 PM
Excel VBA: Worksheet cell .Text property: 1024 bytes text len limit loyso Excel Programming 7 May 3rd 05 02:51 PM
How do i refer to the text typed in a combobox? john q public[_6_] Excel Programming 2 October 28th 04 08:36 PM


All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"