ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   referencing commandbuttons as OLEObjects (https://www.excelbanter.com/excel-programming/402897-referencing-commandbuttons-oleobjects.html)

Bert[_2_]

referencing commandbuttons as OLEObjects
 
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.



Peter T

referencing commandbuttons as OLEObjects
 
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

"Bert" wrote in message
...
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.





Jim Thomlinson

referencing commandbuttons as OLEObjects
 
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...
--
HTH...

Jim Thomlinson


"Bert" wrote:

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.





All times are GMT +1. The time now is 11:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com