referencing commandbuttons as OLEObjects

B

Bert

I want to be able to manipulate and get information about a large number of
commandbuttons using something like:
x = Worksheets(2).OLEObjects.Count
For b = 1 To x
xx = Worksheets(2).OLEObjects.Item(b).BackColor
Next b
This generates a error. (Although xx =
Worksheets(2).OLEObjects.Item(b).Name does not)
The only objects in the OLEObjects collection are commandbuttons.
How can I make this work?
Thanks.
 
P

Peter T

change
xx = Worksheets(2).OLEObjects.Item(b).BackColor
to
xx = Worksheets(2).OLEObjects.Item(b).Object.BackColor
or
xx = Worksheets(2).OLEObjects.(b).BackColor

you could loop like this

dim ole as OLEObject

for each ole in Activeworkbook.Worksheets(2).OLEObjects
xx = ole.Object.Backcolor
next

By default, backcolors of OLEObjects are sytem colours, eg
vbButtonFace = -2147483633 (&H8000000F)

Regards,
Peter T
 
J

Jim Thomlinson

Give this a try...

Sub test()
Dim ctl As OLEObject

For Each ctl In Sheet1.OLEObjects
MsgBox ctl.Object.BackColor
Next ctl
End Sub

Your code will work but it needs to refernece the object then the backcolor...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top