I would like to write a VBA program that parses all the elements of a worksheet except the 2-dimensional data table.
That means, I want to go through all the charts, buttons, checkboxs, etc. if they exist. I would like this list to be exhaustive. So the 1st question is what collections to go through.
One option is ActiveSheet.Shapes
, another option is ActiveSheet.OLEObjects
, I don't know if there is anything else... Could anyone tell me which one covers everything?
Once an item is identified, I want to determine if it is a chart, button, checkbox... I realize that the following code doesn't achieve it: it prints always Shape
.
For Each sShape In ActiveSheet.Shapes
MsgBox TypeName(sShape)
Next
Does anyone know how to show the type of an item?
As follow up from MSDN (Shape and OLEObject):
OLEObject Object:
Shape:
So,
ActiveSheet.Shapes
includeActiveSheet.OLEObjects
.Both collections doesn't include Tables, which are part of
ListObjects
collection.So, you want
Shapes
collection. Following code prints types of all shapes in active sheet:Possible output of subroutine:
Notes:
s.Type
represents type ofShape
object and returns MsoShapeType Enumerations.Type = msoOLEControlObject
(OleObject), partTypeName(s.OLEFormat.Object.Object)
returns name ofOleObject
type, like "CheckBox", "Button" and etc.s.Type = msoFormControl
(Form control), parts.FormControlType
returns XlFormControl Enumeration