Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Dim sheet objects

Hello,
I'm trying to Declare worksheet Comboboxes (from Control Toolbox) as object
variables, but I don't know how to refer to them!
Dim CoBo as MSForms.Combobox
doesn't work on a worksheet, CoBo turns to Nothing and and I get a Type
Mismatch Error. I found that Controls are referred to as OLEObjects but I
can't find information how to declare the variable.
For Each CoBo In Worksheets("Calculation").OLEObjects
CoBo.Clear
If Left(CoBo.Name, 4) = "Curr" Then
CoBo.List = CurrVar
End If
Next

Thanks for help!
Mats
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Dim sheet objects


"Mats Samson" wrote in message
...
Hello,
I'm trying to Declare worksheet Comboboxes (from Control Toolbox) as

object
variables, but I don't know how to refer to them!
Dim CoBo as MSForms.Combobox
doesn't work on a worksheet, CoBo turns to Nothing and and I get a Type
Mismatch Error. I found that Controls are referred to as OLEObjects but I
can't find information how to declare the variable.
For Each CoBo In Worksheets("Calculation").OLEObjects
CoBo.Clear
If Left(CoBo.Name, 4) = "Curr" Then
CoBo.List = CurrVar
End If
Next


Hi,

The Object property of an OLEObject, er, object returns the inner object:

Dim obj As OLEObject
For Each obj In Worksheets("Calculation").OLEObjects
If TypeOf obj.Object Is MSForms.ComboBox Then
'...Do your stuff...
End If
Next

HTH

Robert


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dim sheet objects

Dim obj as OleObject
Dim CoBo as MSForms.Combobox
For Each obj In Worksheets("Calculation").OLEObjects
if typeof Obj.Object is MSforms.Combobox then
set CoBo = Obj.Object
if Left(CoBo.Name,4) = "Curr" then
CoBo.Clear
CoBo.List = CurrVar
end if
End If
Next

Or if only Comboboxes have the Name Curr

Dim obj as OleObject
For Each obj In Worksheets("Calculation").OLEObjects
if Left(Obj.Name,4) = "Curr" then
Obj.Object.Clear
Obj.Object.List = CurrVar
End If
Next

Using the Cobo variable dim'd as MSForms.Combobox could also be added.

Note in xl97, the OleObject Name and the Combobox Name might not agree.

--
Regards,
Tom Ogilvy

"Mats Samson" wrote in message
...
Hello,
I'm trying to Declare worksheet Comboboxes (from Control Toolbox) as

object
variables, but I don't know how to refer to them!
Dim CoBo as MSForms.Combobox
doesn't work on a worksheet, CoBo turns to Nothing and and I get a Type
Mismatch Error. I found that Controls are referred to as OLEObjects but I
can't find information how to declare the variable.
For Each CoBo In Worksheets("Calculation").OLEObjects
CoBo.Clear
If Left(CoBo.Name, 4) = "Curr" Then
CoBo.List = CurrVar
End If
Next

Thanks for help!
Mats



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Dim sheet objects

Thank you guys, it worked fine!
An extra question?! A little bit academic perhaps but I'm curious to learn.
Lets say I have 100 labels each in 3 multipage pages.
If I would like to disable 1/3 of all labels, from a performance point of
view,
what is best?
1. Use a procedure as the below one to search through all labels to find the
right label.
2. Write 100 lines with Labelx.Enable = False
In the first case, Excel has to work more, especially if it would be a
procedure that is frequently used, the performance "drops".
In the second case my file will grow and there is an overall performance drop
but as the address of each label is specifically written, Excel doesn't need
to look
in all 300 labels.
Finally is there a way of "attach" the labels to the page "container" so I may
use the procedure on the current page only? Why run a procedure on a page
that is not visible/used?
Regards
Mats

"Tom Ogilvy" wrote:

Dim obj as OleObject
Dim CoBo as MSForms.Combobox
For Each obj In Worksheets("Calculation").OLEObjects
if typeof Obj.Object is MSforms.Combobox then
set CoBo = Obj.Object
if Left(CoBo.Name,4) = "Curr" then
CoBo.Clear
CoBo.List = CurrVar
end if
End If
Next

Or if only Comboboxes have the Name Curr

Dim obj as OleObject
For Each obj In Worksheets("Calculation").OLEObjects
if Left(Obj.Name,4) = "Curr" then
Obj.Object.Clear
Obj.Object.List = CurrVar
End If
Next

Using the Cobo variable dim'd as MSForms.Combobox could also be added.

Note in xl97, the OleObject Name and the Combobox Name might not agree.

--
Regards,
Tom Ogilvy

"Mats Samson" wrote in message
...
Hello,
I'm trying to Declare worksheet Comboboxes (from Control Toolbox) as

object
variables, but I don't know how to refer to them!
Dim CoBo as MSForms.Combobox
doesn't work on a worksheet, CoBo turns to Nothing and and I get a Type
Mismatch Error. I found that Controls are referred to as OLEObjects but I
can't find information how to declare the variable.
For Each CoBo In Worksheets("Calculation").OLEObjects
CoBo.Clear
If Left(CoBo.Name, 4) = "Curr" Then
CoBo.List = CurrVar
End If
Next

Thanks for help!
Mats




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
Add Custom Objects to Sheet Vineeth Excel Discussion (Misc queries) 1 August 1st 09 10:59 AM
Different objects-same sheet gunshybars Excel Discussion (Misc queries) 1 August 29th 08 02:03 PM
Cannot move objects off sheet mapnimad New Users to Excel 1 July 10th 07 11:52 PM
cannot shift objects off sheet Tim Wallace Excel Programming 9 October 17th 05 08:47 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian[_7_] Excel Programming 1 August 26th 04 10:49 PM


All times are GMT +1. The time now is 10:47 PM.

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

About Us

"It's about Microsoft Excel"