Identify the ID/Number of each Text Box Shape

Asked

Viewed 927 times

0

I started using VBA for Powerpoint and needed to start referencing in my code each Shape within the presentation. But I don’t know which is the name of each Shape to reference. How do I know that a text box is Shape(1), Shape(2) or Shape(40).

Detail, I am working with ready Powerpoints, ie, I do not know the order with which each Shape was created.

Is there anywhere I can check the number of each Shape?

  • 1

    What is the change you want to make in each Shape? Is it a massified, or individual change? In this case, it depends on what (content of Shape, color, shape)? Clarify the question better!

  • In fact, I would like to change both text and color as well as replace one Shape by another when necessary. My idea is to generate an advertising material automatically according to some conditions defined by the user, but for this I need to change various slide information

  • I still don’t quite understand one thing: you want to: (1) at runtime, without human supervision, figure out the type and reference of all Shapes and automatically apply changes to some of them, or you want (2) while programming the code, with an open-example file, figure out how to reference one or the other way you see in that particular file, to try out what you can do with THAT Powerpoint presentation text box that is open in front of you?

  • I am wanting to do the 2. Given a presentation, change a specific Shape as per my code instructions. For this, I need to know how to reference each Hape of the presentation and this is what I’m not getting

1 answer

0

Text Boxes

If you want to get only from text boxes as from the image below:

Teste

The estate .HasTextFrame can be used in a loop in all presentations and shapes.

Code

Dim sld As Slide
Dim shp As Shape

    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes

            If shp.HasTextFrame Then
                Debug.Print "Texto: " & shp.TextFrame2.TextRange & " " _
                ; "ID: " & shp.Id & " " _
                ; "Nome: " & shp.Name
            End If

Next shp
Next sld

Todos os Shapes

For all presentation shapes, you can get the Type, ID and Name.

Code

Dim sld As Slide
Dim shp As Shape
Dim sr As Series
Dim txt As Chart

    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
                Debug.Print "Tipo: " & shp.Type & " " _
                ; "ID: " & shp.Id & " " _
                ; "Nome: " & shp.Name
Next shp
Next sld

Type List

+----------------------+-------+----------------------------------+
|         Nome         | Valor |            Descrição             |
+----------------------+-------+----------------------------------+
| msoAutoShape         |     1 | AutoForma.                       |
| msoCallout           |     2 | Texto Explicativo.               |
| msoCanvas            |    20 | Tela.                            |
| msoChart             |     3 | Gráfico.                         |
| msoComment           |     4 | Comentário.                      |
| msoContentApp        |    27 | Suplemento de conteúdo do Office |
| msoDiagram           |    21 | Diagrama.                        |
| msoEmbeddedOLEObject |     7 | Objeto OLE incorporado.          |
| msoFormControl       |     8 | Controle de formulário.          |
| msoFreeform          |     5 | Forma Livre.                     |
| msoGraphic           |    28 | Elemento gráfico                 |
| msoGroup             |     6 | Grupo.                           |
| msoIgxGraphic        |    24 | Gráfico SmartArt                 |
| msoInk               |    22 | Tinta                            |
| msoInkComment        |    23 | Comentário à tinta               |
| msoLine              |     9 | Linha                            |
| msoLinkedGraphic     |    29 | Gráfico vinculado                |
| msoLinkedOLEObject   |    10 | Objeto OLE vinculado             |
| msoLinkedPicture     |    11 | Imagem vinculada                 |
| msoMedia             |    16 | Mídia                            |
| msoOLEControlObject  |    12 | Objeto de controle OLE           |
| msoPicture           |    13 | Imagem                           |
| msoPlaceholder       |    14 | Espaço reservado                 |
| msoScriptAnchor      |    18 | Âncora de script                 |
| msoShapeTypeMixed    |    -2 | Tipo de forma misto              |
| msoTable             |    19 | Tabela                           |
| msoTextBox           |    17 | Caixa de texto                   |
| msoTextEffect        |    15 | Efeito de texto                  |
| msoWebVideo          |    26 | Vídeo da Web                     |
+----------------------+-------+----------------------------------+

Note. 1: See The Shapes documentation for more information

Note. 2: To view what is printed with the command Debug.Print, you need to enable the Immediate Verification dialog.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.