VBA - manipulate Collection of shapes

D4rwin

Board Regular
Joined
Mar 31, 2014
Messages
91
Hi,
I have a sheet with several shapes (100+) and I need to manipulate the transparency of each shape based on the text in each shape.
Currently I am using a For Loop to go through each shape to test if the text equals a specific string. If so, the shape transparency is modified.
However, I suspect that this is quite a cumbersome operation for VBA as it takes a few seconds to process each shape during the loop. I am wondering if it: a) is possible to add each shape matching the text criteria to a collection, and b) is possible to manipulate the shape transparency of each shape in the collection in order to speed it up.

Eventhough the following code will not work, it demonstrates what I'm trying to achieve:

Code:
dim shp as shape
dim colShapes as new collection

for each shp in activesheet.shapes
     if shp.textframe2.textrange.text = "string" then
          colShapes.add shp
     end if
next shp

colShapes.fill.transparency = 0.8

Again, the purpose is to speed up the processing time so that VBA will apply the transparency modification in one sweep.
All suggestions/comments are welcome.
Thanks
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Watch MrExcel Video

Forum statistics

Threads
1,109,518
Messages
5,529,309
Members
409,862
Latest member
lbisacca
Top