excel VBA将ppt幻灯片合并为主ppt幻灯片

axr492tv  于 2023-02-14  发布在  其他
关注(0)|答案(1)|浏览(190)

您好StackoverflowMaven。请帮助,如果有一个VBA脚本,可以合并ppt文件。我有11张幻灯片,1是主幻灯片和10个单独的报告幻灯片。我想VBA代码合并所有单独的报告幻灯片到我的主幻灯片。所有幻灯片都在同一个文件夹中。非常感谢您的任何帮助。
已尝试搜索,但无法在线找到任何解决方案。

cuxqih21

cuxqih211#

给你。

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

相关问题