首页 > 解决方案 > 如何将 VBA 代码应用于所有 Powerpoint 幻灯片

问题描述

我有兴趣将以下 VBA 代码应用于我的 powerpoint 演示文稿中的所有幻灯片。下面的代码将我的表格调整为我需要的确切规格。您对如何在我的演示文稿中应用这一点有任何建议吗?提前致谢。

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

标签: vbapowerpoint

解决方案


以下宏将循环播放活动演示文稿中的每张幻灯片。然后,对于每张幻灯片,它将遍历幻灯片中的每个形状,直到找到一个表格,然后格式化表格。

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

推荐阅读