Home > Net >  Vba ArrayList or Array Find method
Vba ArrayList or Array Find method

Time:12-31

I am manipulating through excel vba powerpoint slides. I create shapes ("rectangle","textbox") but it's hard to find their proper index numbers to manipulate them further. I know I can touch them through Slides(1).Shapes(i) index numbers, as I create ppt slides from zero. But I want to manipulate them immediately after creating. In Paste method I found that I can write code Paste.Select then ActiveWindow.Selection gives me the shape. But I could not do it with AddShapes(msoRectangle...)Select. That's why I want to bring all object names inside slide to an arraylist, then search inside that array step by step with words like Rectangle, TextBox to see them. For my curiosity, the ArrayList.Contains "TextBox" gives "False" even though there is the shape named "TextBox 1". I know if I will write "TextBox 1" it will give true value. But i need through macro to find(what:,LookIn), or Like "TextBox*"... I also used Filter method of an array, I have also taken the values inside another array, but it gives TypeMismatch 13 error.

Dim shpNameArr As Object
Set shpNameArr = CreateObject("System.Collections.ArrayList")

For each Item in .Slides(1).Shapes
    shpNameArr.Add Item.Name
Next
For Each Item in shpNameArr
    MsgBox Item
Next
For Each Item in shpNameArr
    MsgBox shpNameArr.Contains("TextBox")
    shpNameArrW = Filter(Item,"TextBox")
    MsgBox shpNameArrW
Next

CodePudding user response:

Shapes.AddShape() returns the shape you just added, so you can use that directly without needing to search through the shapes on the slide.

https://docs.microsoft.com/en-us/office/vba/api/powerpoint.shapes.addshape

Eg:

Dim shp As Shape
Set shp= Slides(1)Shapes.AddShape(msoRect...)

now you can work directly with shp

  • Related