View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default how to use object variable to change the property of a

Dim ctrl as Control
i = 1
for each ctrl in Userform1.Controls
if typeof ctrl is MSForms.Label then
ctrl.Caption = "Item" & i
i = i + 1
end if
Next

--
Regards,
Tom Ogilvy

"Fendic" wrote in
message ...

Hi all,

I'd like to like to assign a number of Labels into an array, so that i
can use loop to change the caption of each Label. I tried testing by
using object variable as follows:

Dim testLabel As Label
testLabel = myLabel

myLabel is a Label i created in a form. but if i run the code, an error
would show that ''object variable or 'with' block variable is not
defined'', which i don't understand, cos apparently testLabel is
clearly defined.

However, if i change it to be:

Dim testLabel
testLabel = myLabel

it works, but testLabel is actually a string, in stead of a label, thus
i'll not be able to change the caption of it.

can anyone help please. it sounds easy, but i've been struggling for
days, and just can't get the syntax right. thanks

All the best,
Fendic


--
Fendic
------------------------------------------------------------------------
Fendic's Profile:

http://www.excelforum.com/member.php...o&userid=23959
View this thread: http://www.excelforum.com/showthread...hreadid=389989