Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Create a collection of controls

I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX controls) and I want
to add these objects to a collection. How do I do this? What I have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example code on how to do
this? Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Create a collection of controls

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX controls)
and I want
to add these objects to a collection. How do I do this? What I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example code on
how to do
this? Thanks much in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Create a collection of controls

Thanks Chip!
Shouldn't I be able to obtain a count of items in the collection using:

MsgBox colObject.Count

In a test there are three controls in the sheet, but the count returns zero...


"Chip Pearson" wrote:

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX controls)
and I want
to add these objects to a collection. How do I do this? What I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example code on
how to do
this? Thanks much in advance.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Create a collection of controls

Quartz,

Debug.Print colObject.Count

returns the correct count for me. Step through your code to
ensure that the items are indeed added to the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
Thanks Chip!
Shouldn't I be able to obtain a count of items in the
collection using:

MsgBox colObject.Count

In a test there are three controls in the sheet, but the count
returns zero...


"Chip Pearson" wrote:

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX
controls)
and I want
to add these objects to a collection. How do I do this? What
I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example code
on
how to do
this? Thanks much in advance.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Create a collection of controls

Chip,
The items are NOT being added. I am using the exact code, what am I doing
wrong? Do I need a library reference?

I very much appreciate your assistance...

"Chip Pearson" wrote:

Quartz,

Debug.Print colObject.Count

returns the correct count for me. Step through your code to
ensure that the items are indeed added to the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
Thanks Chip!
Shouldn't I be able to obtain a count of items in the
collection using:

MsgBox colObject.Count

In a test there are three controls in the sheet, but the count
returns zero...


"Chip Pearson" wrote:

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX
controls)
and I want
to add these objects to a collection. How do I do this? What
I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example code
on
how to do
this? Thanks much in advance.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Create a collection of controls

I can't think of a reason that they are not being added. Do you
have an On Error Resume Next in your procedure. If you do,
comment it out so you can see the run time error (if any) that is
causing the error. The only thing I can think of is that you are
attempting to add an item to the collection and the key value
already exists in the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"quartz" wrote in message
...
Chip,
The items are NOT being added. I am using the exact code, what
am I doing
wrong? Do I need a library reference?

I very much appreciate your assistance...

"Chip Pearson" wrote:

Quartz,

Debug.Print colObject.Count

returns the correct count for me. Step through your code to
ensure that the items are indeed added to the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
Thanks Chip!
Shouldn't I be able to obtain a count of items in the
collection using:

MsgBox colObject.Count

In a test there are three controls in the sheet, but the
count
returns zero...


"Chip Pearson" wrote:

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in
message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX
controls)
and I want
to add these objects to a collection. How do I do this?
What
I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example
code
on
how to do
this? Thanks much in advance.








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Create a collection of controls

Ah, I see, I added a few ActiveX controls to the sheet and it works fine.
Actually, I'm using Non-ActiveX controls... how would I do that?

"quartz" wrote:

Chip,
The items are NOT being added. I am using the exact code, what am I doing
wrong? Do I need a library reference?

I very much appreciate your assistance...

"Chip Pearson" wrote:

Quartz,

Debug.Print colObject.Count

returns the correct count for me. Step through your code to
ensure that the items are indeed added to the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
Thanks Chip!
Shouldn't I be able to obtain a count of items in the
collection using:

MsgBox colObject.Count

In a test there are three controls in the sheet, but the count
returns zero...


"Chip Pearson" wrote:

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX
controls)
and I want
to add these objects to a collection. How do I do this? What
I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example code
on
how to do
this? Thanks much in advance.






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Create a collection of controls

Chip,
The objects in question work if I dim them as Shapes rather than OLEObject,
but then, I get the ActiveX objects as well. I only want the NON-activeX
items.

Sorry, I have to leave now. I will repost tomorrow if I can't crack it.

Thanks again for your help!!!

"Chip Pearson" wrote:

I can't think of a reason that they are not being added. Do you
have an On Error Resume Next in your procedure. If you do,
comment it out so you can see the run time error (if any) that is
causing the error. The only thing I can think of is that you are
attempting to add an item to the collection and the key value
already exists in the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"quartz" wrote in message
...
Chip,
The items are NOT being added. I am using the exact code, what
am I doing
wrong? Do I need a library reference?

I very much appreciate your assistance...

"Chip Pearson" wrote:

Quartz,

Debug.Print colObject.Count

returns the correct count for me. Step through your code to
ensure that the items are indeed added to the collection.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in message
...
Thanks Chip!
Shouldn't I be able to obtain a count of items in the
collection using:

MsgBox colObject.Count

In a test there are three controls in the sheet, but the
count
returns zero...


"Chip Pearson" wrote:

Quartz,

Try the following code

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As OLEObjects
Dim lX As Long

Set oItems = ActiveSheet.OLEObjects
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, Format(lX, "0")
Next


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"quartz" wrote in
message
...
I am using Office 2003 on Windows XP.

I have several controls on a spreadsheet (non-ActiveX
controls)
and I want
to add these objects to a collection. How do I do this?
What
I
have so far
follows, but ofcourse generates an error:

Dim colObject As New Collection
Dim vItem As Variant
Dim oItems As Controls
Dim lX As Long

Set oItems = ActiveSheet.Controls
For Each vItem In oItems
lX = lX + 1
colObject.Add vItem, lX
Next

Could someone please correct my code or supply example
code
on
how to do
this? Thanks much in advance.









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
how do i create a data collection form in excel? stacy New Users to Excel 1 October 26th 05 08:21 PM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM
How to create controls at runtime Andy Chan Excel Programming 3 August 30th 04 10:07 AM
Create controls dynamically Tom Ogilvy Excel Programming 0 November 24th 03 03:37 PM
Function to create a collection Derek Gadd Excel Programming 4 November 1st 03 03:30 PM


All times are GMT +1. The time now is 12:17 AM.

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"