从其他演示文稿导入幻灯片后未保存Powerpoint演示文稿的VBA项目

VBA Project of Powerpoint Presentation not Saved after importing slides from other presentation

提问人:dawit 提问时间:11/10/2023 最后编辑:dawit 更新时间:11/10/2023 访问量:41

问:

我有一个带有宏的 Powerpoint 演示文稿,它允许用户添加模块,这些模块是大型演示文稿的一部分。主演示文稿和模块都保存为文件。.pptm

使用 Slides.InsertFromFile-Method 将模块导入到主演示文稿中。

有时,在保存演示文稿后,将其关闭并重新打开后,VBA-Project 不再可见:Picture of missing VBA-project

此外,在将演示文稿作为 .zip 文件检查后,事实证明 vbaProject.bin 文件仍然存在:Picture of the directory structure of the .pptm file

此错误不会以可预测的方式发生,但是,如果将更多模块加载到演示文稿中,则发生此错误的可能性会更高。 通过复制主演示文稿从主演示文稿创建模块,删除除构成模块的部分的幻灯片之外的所有幻灯片。因此,所有模块都使用相同的幻灯片母版。

有什么原因可能导致这个错误和解决它的方法吗?

更新:

这是用于导入“模块”的VBA代码。在这种情况下,“模块”只是一个包含幻灯片的 Powerpoint 演示文稿。这些模块可以包含某些幻灯片中的下拉列表的 VBA 代码,在这种情况下,VBA 代码是特定于幻灯片的,用于控制某些用户元素。这些模块在代码中被称为部分,其想法是有选择地从大型演示文稿中导入部分。

Sub ImportSection(sectionName As String, sectionPath As String, sectionId As String)

    Dim iFAP As Presentation, sectionPres As Presentation
    Dim sectionIndex As Long, currSection As Long, currSectionName As String
    Dim slideIndex As Long, currSlideIndex As Long
    Dim LastSlide As Integer

    Set iFAP = ActivePresentation
    On Error Resume Next
    Set sectionPres = GetObject(sectionPath)
    If sectionPres Is Nothing Then
        ' Presentation could not be found
        Wait 3
        GoTo Error
    End If
    
    ' Get the selected section index from the list box
    sectionIndex = GetSectionOrderIndex(sectionName)
    
    If sectionIndex > 1 Then
        With ActivePresentation.SectionProperties
            LastSlide = (.FirstSlide(sectionIndex - 1) + .SlidesCount(sectionIndex - 1)) - 1
        End With
    Else
        Exit Sub
    End If
    
    'Actual import code 
    iFAP.Slides.InsertFromFile sectionPath, LastSlide
    
    With sectionPres.SectionProperties
        For sectionI = 1 To .count
            currSlideIndex = LastSlide + .FirstSlide(sectionI)
            currSectionName = .name(sectionI)
            iFAP.SectionProperties.AddBeforeSlide currSlideIndex, currSectionName
            iFAP.Slides(currSlideIndex).CustomLayout = FindCustomLayout(CleanSectionName(currSectionName))
        Next sectionI
    End With
    
    sectionPres.Close
Error:
End Sub

此外,要导入多个部分,我们在演示文稿中有一个带有复选框的用户表单,我们循环使用上述函数导入每个选中的部分。

Excel VBA 幻灯片

评论

0赞 FaneDuru 11/10/2023
最好在讨论中向我们展示导入幻灯片的代码。那么,您正在谈论幻灯片导入,但是“如果将更多模块加载到演示文稿中”是什么意思?您是在谈论VBA模块还是其他东西?导入的幻灯片是否包含VBA代码?
0赞 dawit 11/10/2023
我添加了代码以导入“模块”或“部分”。这只是一个术语,指的是像书中的一章这样的小演示文稿。大多数代码只是为了将部分标记添加到演示文稿中。导入部分幻灯片的实际代码是一个简单的函数调用。
0赞 John Korchok 11/11/2023
我不清楚你为什么包含一个 Excel 标签,我没有看到任何 Excel 代码。这听起来像是将幻灯片导入到包含代码的演示文稿中。在大多数情况下,更好的做法是将代码保存在 VBA 加载项 (*.ppam) 中,然后在 PowerPoint 中安装它。这样,代码就不会因您对正在处理的演示文稿所做的更改而被清除。

答: 暂无答案