1
votes

I am interested in applying the following VBA code to all slides in my powerpoint presentation. The code below resizes my table to the exact specifications I need. Do you have any advice on how to make this apply throughout my presentation? Thanks in advance.

Sub ResizeAlign()
    With ActiveWindow.Selection.ShapeRange
    .Height = 216
    .Width = 864
    .Left = 48
    .Top = 198
        ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack
    End With
End Sub
2

2 Answers

1
votes

The following macro will loop through each slide within the active presentation. Then, for each slide, it will loop through each shape within the slide until it finds a table, and then it formats the table.

Option Explicit

Public Sub ResizeAlignPresentation()
    Dim currentSlide As Slide
    For Each currentSlide In ActivePresentation.Slides
        ResizeAlignSlide currentSlide
    Next
End Sub

Private Sub ResizeAlignSlide(ByVal target As Slide)
    Dim currentShape As Shape
    For Each currentShape In target.Shapes
        If currentShape.Type = msoTable Then
            ResizeAlignTable currentShape
            Exit For
        End If
    Next
End Sub

Private Sub ResizeAlignTable(ByVal table As Shape)
    With table
        Debug.Assert .Type = msoTable 'if code breaks here, we have a bug!
        .Height = 216
        .Width = 864
        .Left = 48
        .Top = 198
        .ZOrder msoSendToBack
    End With
End Sub
0
votes

I have upped the last answer with this code I created (in need). I needed to run through all SlideMasters, all slides, all textboxes and put them on top. So they will always be in front of pictures etc.

Sub SetInFront()
Dim m, s, t, ma, sl, te

Set ma = ActivePresentation.Designs
For Each m In ma
    Set sl = m.SlideMaster.CustomLayouts
    For Each s In sl
        Set te = s.Shapes
        For Each t In te
            If t.HasTextFrame Then
                t.ZOrder 0
            End If
        Next t
    Next s
Next m

End Sub