Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use object variable to change the property of a


Hi all,

I'd like to like to assign a number of Labels into an array, so that
can use loop to change the caption of each Label. I tried testing b
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 erro
would show that ''object variable or 'with' block variable is no
defined'', which i don't understand, cos apparently testLabel i
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, thu
i'll not be able to change the caption of it.

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

All the best,
Fendi

--
Fendi
-----------------------------------------------------------------------
Fendic's Profile: http://www.excelforum.com/member.php...fo&userid=2395
View this thread: http://www.excelforum.com/showthread.php?threadid=38998

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use object variable to change the property of a


The code is working, but there's still one problem that it changes ALL
labels in the user form. What if i only want to change some of them?(10
out of 21) that's why i want to assign them into an array, so that i can
get control only part of them. I appreciate your help, Tom. any idea
about it?


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to use object variable to change the property of a

Dim arrLbl(1 to 10) as MsForms.Label
for i = 1 to 10
set arrLbl(i) = Userform1.Controls("Label" & i)
Next

for i = 1 to 10
arrLbl(i).Caption = "Item" & i
Next


as an example. You would have to work out how to identify which labels to
assign to the array. the above is just an example.

--
Regards,
Tom Ogilvy


"Fendic" wrote in
message ...

The code is working, but there's still one problem that it changes ALL
labels in the user form. What if i only want to change some of them?(10
out of 21) that's why i want to assign them into an array, so that i can
get control only part of them. I appreciate your help, Tom. any idea
about it?


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

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use object variable to change the property of a


you are a genius. Thanks so much, Tom!!! :) :) :

--
Fendi
-----------------------------------------------------------------------
Fendic's Profile: http://www.excelforum.com/member.php...fo&userid=2395
View this thread: http://www.excelforum.com/showthread.php?threadid=38998

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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 04:58 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"