【问题标题】:VBA to merge ppt slides into master ppt slideVBA合并ppt幻灯片到主ppt幻灯片
【发布时间】:2023-02-10 08:51:29
【问题描述】:

您好 Stackoverflow 专家。如果有可以合并ppt文件的VBA脚本,请帮助。 我有 11 张幻灯片,其中 1 张是主幻灯片,10 张是单独的报告幻灯片。 我想要一个 VBA 代码将所有单独的报告幻灯片合并到我的母版幻灯片中。 所有幻灯片都在同一个文件夹中。非常感谢您提供的任何帮助。

已尝试搜索但无法在线找到任何解决方案。

【问题讨论】:

  • 幻灯片如何“在同一文件夹中”?幻灯片是演示文稿的一部分。
  • 所有幻灯片都在同一个文件夹中。是的,它是一部分……幻灯片是演示文稿的标题页……谢谢

标签: excel vba powerpoint


【解决方案1】:

干得好。

Sub InsertAllSlides()
'  Insert all slides from all presentations in the same folder as this one
'  INTO this one; do not attempt to insert THIS file into itself, though.

    Dim vArray() As String
    Dim x As Long

    ' Change "*.PPT" to "*.PPTX" or whatever if necessary:
    EnumerateFiles ActivePresentation.Path & "", "*.pptx", vArray

    With ActivePresentation
        For x = 1 To UBound(vArray)
            If Len(vArray(x)) > 0 Then
                .Slides.InsertFromFile vArray(x), .Slides.Count
            End If
        Next
    End With

End Sub

Sub EnumerateFiles(ByVal sDirectory As String, _
    ByVal sFileSpec As String, _
    ByRef vArray As Variant)
    ' collect all files matching the file spec into vArray, an array of strings

    Dim sTemp As String
    ReDim vArray(1 To 1)

    sTemp = Dir$(sDirectory & sFileSpec)
    Do While Len(sTemp) > 0
        ' NOT the "mother ship" ... current presentation
        If sTemp <> ActivePresentation.Name Then
            ReDim Preserve vArray(1 To UBound(vArray) + 1)
            vArray(UBound(vArray)) = sDirectory & sTemp
        End If
        sTemp = Dir$
    Loop

End Sub

【讨论】:

    猜你喜欢
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2010-12-03
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 2013-04-09
    相关资源
    最近更新 更多