如何使用VBA将PowerPoint部分复制到新的演示文稿

乔尔·佩辛格

我们通常使用Powerpoint来促进我们的实验。我们在PowerPoint中使用“部分”将幻灯片组组合在一起以完成每个实验任务。移动各个部分以平衡实验的任务顺序已经做了很多工作!

我认为我们可以在CSV或数组中预先定义一个平衡顺序(使用代表该顺序的数字字符串)(尚未在VBA中建立平衡顺序)。然后使用VBA移动部分并保存每个订单的文件。我对使用VBA感到非常生疏,但我认为我有一个很好的开始。问题在第24行。我不知道如何将本节复制到新的演示文稿中。有谁足够熟悉以引导我走上正确的道路。

Sub Latin_Square()
    Dim amountOfSubjects As Integer
    'Declare the amount of subjects you have in your study
    amountOfSubjects = 14

    Dim filePath As String
    filePath = "C:/1.pptx"

    Dim amountofsections As Integer
    Dim i As Integer
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim desktopPath As String
    'find out where user's desktop is
    desktopPath = Environ("UserProfile") & "\Desktop\"


    Dim oldPresentation As Presentation
    Dim newPresentation As Presentation
    'open the target presentation
    Set oldPresentation = Presentations.Open("C:\1.pptx")
    For i = 1 To oldPresentation.Slides.Count
        oldPresentation.Slides.Item(i).Copy
        newPresentation.Item(1).Slides.Paste
    Next i
    oldPresentation.Close

    With newPresentation
        .SaveCopyAs _
            FileName:=fso.BuildPath(desktopPath, "Test" & 1 & ".pptx"), _
            FileFormat:=ppSaveAsOpenXMLPresentation
    End With

End Sub
阿斯格

如果要复制包含其部分的幻灯片,则不能newPresentation.Slides.Paste粘贴幻灯片,因为这会将最后一张幻灯片的部分移到新粘贴的幻灯片上。

这是一个示例,如何逐张复制幻灯片,检查幻灯片是否是某节的开头,然后如何添加新节:

Public Sub CopySlidesWithSections()
    Dim oldPresentation As Presentation, newPresentation As Presentation
    Dim oldSlide As Slide, newSlide As Slide
    Dim oldSectionProperties As SectionProperties, newSectionProperties As SectionProperties
    Dim i As Integer

    Set oldPresentation = ActivePresentation
    Set oldSectionProperties = oldPresentation.SectionProperties

    Set newPresentation = Application.Presentations.Add
    Set newSectionProperties = newPresentation.SectionProperties

    For Each oldSlide In oldPresentation.Slides
        oldSlide.Copy
        ' Would lead to wrong sectioning: Set newSlide = newPresentation.Slides.Paste.Item(1)
        Set newSlide = newPresentation.Slides.Paste(newPresentation.Slides.Count + 1).Item(1)

        For i = 1 To oldSectionProperties.Count
            If oldSectionProperties.FirstSlide(i) = oldSlide.SlideIndex Then
                newSectionProperties.AddBeforeSlide _
                    newSlide.SlideIndex, _
                    oldSectionProperties.Name(i)
                Exit For
            End If
        Next i
    Next oldSlide
End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何根据特定的幻灯片输入将幻灯片从现有演示文稿复制到新演示文稿?

使用Powershell将幻灯片从一种Powerpoint演示文稿复制到另一种幻灯片

在VBA powerpoint中如何将新幻灯片添加到空白演示文稿

PowerPoint VBA:如何将每张幻灯片单独保存为新演示文稿?

如何使用VBA将文本框添加到PowerPoint演示文稿

如何将幻灯片从一个演示文稿复制到另一个演示文稿?

使用Open XML SDK将幻灯片从一个演示文稿复制到另一个演示文稿

使用VBA将数据从Excel复制到Powerpoint

在Excel中使用VBA从PowerPoint模板创建新的PowerPoint演示文稿

如何使用Excel VBA和userform编辑嵌入在Excel中的PowerPoint演示文稿

使用VBA和Excel生成Powerpoint演示文稿

如何使用 Node 将数据添加到现有的 PowerPoint 演示文稿?

循环播放Powerpoint演示文稿的选定部分

从Word VBA编辑PowerPoint演示文稿页脚

回形针:如何上载Powerpoint演示文稿文件

使用Python制作PowerPoint演示文稿?

Excel VBA将值复制到新的

Excel Vba将图片复制到新表

将幻灯片从一个Google幻灯片演示文稿复制到另一个幻灯片中

将新模板应用于Mac上已经存在的PowerPoint演示文稿

VBA运行时错误:将PowerPoint演示文稿另存为PDF

VBA 从 Excel 复制到 PowerPoint(不是“复制和粘贴”)

录制PowerPoint演示文稿时如何获得演示者视图?

如何在Excel VBA中获取打开的PowerPoint演示文稿的处理程序

无法使用VBA从Excel打开现有的PowerPoint演示文稿(2016)

如何将变量复制到新的Linux Shell?

Laravel - 如何将集合复制到新变量

如何将工作目录复制到新提交

如何将完整架构复制到新架构