0
votes

I work from excel, and i open several powerpoint in a loop inside a directory, in vba. While i run the macro (from excel), I make a loop within every shape inside every slides in powerpoints presentation.

I stop the macro to see if AutoShapeType = -2, and i select it in vba just to check visualy if the shape is the right shape i want. Otherwise, if the selected shape doesn't seems right, I select it manually and I want to know how the syntaxe to get the id of the current selected shape, in order to name it.

Set PPtapp = CreateObject("Powerpoint.Application")
PPtapp.Visible = True
Dim sld As Slide
Dim numslide As Long
Dim nbslide As Long
Dim WVL_CptShape As Integer

'list of every powerpoint path
ppt = ThisWorkbook.Worksheets("Template").Range("A" & i).Value

For i = 2 To ThisWorkbook.Worksheets("Template").Range("A65536").End(xlUp).Row + 1
    Set PptDoc = PPtapp.Presentations.Open(ppt)
    With PptDoc
        For Each sld In PptDoc.Slides
            For WVL_CptShape = 1 To .Slides(sld.SlideNumber).Shapes.Count
                WVL_Id = .Slides(sld.SlideNumber).Shapes(WVL_CptShape).ID
                If PptDoc.Slides(sld.SlideNumber).Shapes(WVL_CptShape).AutoShapeType = -2 Then
                    'I select the shape to see visualy if it's a good selection and I stop the macro
                    PptDoc.Slides(sld.SlideNumber).Shapes(WVL_CptShape).Select
                    Stop
                    'if the selection doesnt seems right I select the right shape manualy
                    'Question : in vba, i want to change the name of the selected shape. 
                    'But i don't know how to get the id of the current selected shape (see below : ID_OF_CURRENT_SHAPE_SELECTED_MANUALY)
                    'I would like to rename it, in order to recognize it easily next time
                     PptDoc.Slides(sld.SlideNumber). Shapes(ID_OF_CURRENT_SHAPE_SELECTED_MANUALY).Selection.Name = "Myshape"
                end if
            Next WVL_CptShapeNext 
        sld.Close 
    End With
Next
PPtapp.Quit
Set PPtapp = Nothing
1
Are you looking for a method how to read the Shape.Type for all shapes in all slided ?Shai Rado
I am looking for an instruction, that get selected shape : I loop all the shape, if 1 shape (e.g. shape ID 1) is AutoShapeType = -2 i stop the macro. If this shape isn't the shape i was looking for. I select another shape (e.g. shape ID 2) (manualy on the slide), and i want the macro to get that new one id shape (shape ID 2). thank you :)stan

1 Answers

0
votes
    Set PptDoc = PPtapp.Presentations.Open(ppt)
    With PptDoc
        For Each sld In PptDoc.Slides
            For WVL_CptShape = 1 To sld.Shapes.Count
                WVL_Id = sld.Shapes(WVL_CptShape).ID
                If sld.Shapes(WVL_CptShape).AutoShapeType = -2 Then
                    'I select the shape to see visualy if it's a good selection and I stop the macro
                    sld.Shapes(WVL_CptShape).Select
                    Stop

' And to change the name of the shape:
sld.Shapes(WVL_CptShape).Name = "New name for shape"
' or better, in case you selected a different shape:

ActiveWindow.Selection.ShapeRange(1).Name = "New name for shape"

In this type of situation, you want to work with the shape's Index, not its ID.

Note that you can iterate through the shapes collection on a slide just as you can iterate through the slides collection in a presentation. It makes the code a lot simpler to write and to follow:

Set PptDoc = PPtapp.Presentations.Open(ppt)
With PptDoc
    For Each sld In PptDoc.Slides
        For each shp in sld.shapes
            If shp.AutoShapeType = -2 Then
                'I select the shape to see visualy if it's a good selection and I stop the macro
                shp.Select
                Stop