Results 1 to 3 of 3

Thread: Select all text boxes and shapes with texts on current slide

  1. #1

    Select all text boxes and shapes with texts on current slide

    Hello!

    Let me start by saying I'm not a programmer, I have absolutely no idea about how all this coding works, it's all sorcery to me. x)

    I've been using ChatGPT just fine until now when it comes to creating simple working macros for Word, Powerpoint, etc. This simple task, however, seems impossible for ChatGPT. I've tried, literally, over 30 different codes generated by ChatGPT and none of them work correctly.

    So basically:


    1. Version of the program: Powerpoint 365 (European Spanish version if that helps)
    2. What you want it to do: I want a simple macro that, when ran, selects all of the text boxes and any other type of shape or object that contains text within, and have them all selected simultaneously. This is because I need to copy/paste them in another Powerpoint file, maintaining the same position, font size, format, etc.
    3. Cell references, bookmark names, column letters, row numbers, worksheets, styles, whatever pertains to the information at hand: N/A
    4. Error messages if any: Oh dear Lord, all of them. The most common one can be loosely translated as "-2147467263 (80004001): the specified collection index is out of limits".
    5. If not the entire code, then at least some of it:

      This one generates the aforementioned error:
      Sub SeleccionarCuadrosDeTexto()
          Dim slide As slide
          Dim shape As shape
          Dim selectedShapes() As shape
          Dim i As Integer
          
          ' Obtiene la referencia a la diapositiva actual
          Set slide = ActiveWindow.View.slide
          
          ' Inicializa el contador de formas seleccionadas
          i = 0
          
          ' Recorre todos los objetos en la diapositiva
          For Each shape In slide.Shapes
              ' Verifica si el objeto es un cuadro de texto
              If shape.Type = msoTextBox Then
                  ' Aumenta el tamaño de la matriz y agrega la forma a la matriz
                  ReDim Preserve selectedShapes(1 To i + 1)
                  Set selectedShapes(i + 1) = shape
                  i = i + 1
              End If
          Next shape
          
          ' Deselecciona cualquier objeto seleccionado actualmente
          slide.Shapes.Range(Array()).Select
          
          ' Selecciona todas las formas de la matriz
          For i = LBound(selectedShapes) To UBound(selectedShapes)
              selectedShapes(i).Select (msoTrue)
          Next i
      End Sub
      Now the following does work... partially, cause it only selects ONE textbox, not all of them, and does not select other shapes or objects that contain text:

      Sub SeleccionarCuadrosDeTexto()
          Dim slide As slide
          Dim shape As shape
          
          ' Obtiene la referencia a la diapositiva actual
          Set slide = ActiveWindow.View.slide
          
          ' Deselecciona cualquier objeto seleccionado actualmente
          On Error Resume Next
          slide.Shapes.Range(Array()).Select
          On Error GoTo 0
          
          ' Recorre todos los objetos en la diapositiva
          For Each shape In slide.Shapes
              ' Verifica si el objeto es un cuadro de texto
              If shape.HasTextFrame Then
                  ' Selecciona el cuadro de texto
                  shape.Select (msoTrue)
              End If
          Next shape
      End Sub
      I cannot fathom why such a simple task is so complicated to automate on Powerpoint.

      Any help would be very much appreciated!

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,095
    Location
    In this line
     shape.Select (msoTrue)
    msoTrue means DEselect any previously selected shapes

    Change that line to
    Sub SeleccionarCuadrosDeTexto()    Dim slide As slide
        Dim shape As shape
        
        ' Obtiene la referencia a la diapositiva actual
        Set slide = ActiveWindow.View.slide
    
    
        
        ' Recorre todos los objetos en la diapositiva
        For Each shape In slide.Shapes
            ' Verifica si el objeto es un cuadro de texto
            If shape.HasTextFrame Then
                ' Selecciona el cuadro de texto
                shape.Select (msoFalse)
            End If
        Next shape
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,234
    Location
    Welcome to VBAX wizarddani. If there's an issue with ChatGPT it is more often than not, that you need to ask very specific questions, to receive a correct answer. John has (as usual) found the issue for you.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •