提问人:dawit 提问时间:11/10/2023 最后编辑:dawit 更新时间:11/10/2023 访问量:41
从其他演示文稿导入幻灯片后未保存Powerpoint演示文稿的VBA项目
VBA Project of Powerpoint Presentation not Saved after importing slides from other presentation
问:
我有一个带有宏的 Powerpoint 演示文稿,它允许用户添加模块,这些模块是大型演示文稿的一部分。主演示文稿和模块都保存为文件。.pptm
使用 Slides.InsertFromFile-Method 将模块导入到主演示文稿中。
有时,在保存演示文稿后,将其关闭并重新打开后,VBA-Project 不再可见:
此外,在将演示文稿作为 .zip 文件检查后,事实证明 vbaProject.bin 文件仍然存在:
此错误不会以可预测的方式发生,但是,如果将更多模块加载到演示文稿中,则发生此错误的可能性会更高。 通过复制主演示文稿从主演示文稿创建模块,删除除构成模块的部分的幻灯片之外的所有幻灯片。因此,所有模块都使用相同的幻灯片母版。
有什么原因可能导致这个错误和解决它的方法吗?
更新:
这是用于导入“模块”的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
此外,要导入多个部分,我们在演示文稿中有一个带有复选框的用户表单,我们循环使用上述函数导入每个选中的部分。
答: 暂无答案
评论