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:
- Version of the program: Powerpoint 365 (European Spanish version if that helps)
- 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.
- Cell references, bookmark names, column letters, row numbers, worksheets, styles, whatever pertains to the information at hand: N/A
- 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".
- If not the entire code, then at least some of it:
This one generates the aforementioned error:
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 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
I cannot fathom why such a simple task is so complicated to automate on Powerpoint.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
Any help would be very much appreciated!