如何使用VBA将powerpoint部分复制到新演示文稿
我们通常使用powerpoint来促进我们的实验。我们在powerpoint中使用“部分”来为每个实验任务将幻灯片组放在一起。移动部分以平衡实验的任务顺序已经做了很多工作 我想我们可以在CSV或数组中预定义平衡顺序(使用表示顺序的数字字符串)(尚未在VBA中构建)。然后使用VBA移动节并保存每个订单的文件。我对使用VBA很生疏,但我认为我有一个很好的开始。问题在第24行。我不知道如何将该部分复制到新的演示文稿中。是否有足够熟悉的人引导我走上正确的道路如何使用VBA将powerpoint部分复制到新演示文稿,vba,powerpoint,sections,copying,Vba,Powerpoint,Sections,Copying,我们通常使用powerpoint来促进我们的实验。我们在powerpoint中使用“部分”来为每个实验任务将幻灯片组放在一起。移动部分以平衡实验的任务顺序已经做了很多工作 我想我们可以在CSV或数组中预定义平衡顺序(使用表示顺序的数字字符串)(尚未在VBA中构建)。然后使用VBA移动节并保存每个订单的文件。我对使用VBA很生疏,但我认为我有一个很好的开始。问题在第24行。我不知道如何将该部分复制到新的演示文稿中。是否有足够熟悉的人引导我走上正确的道路 Sub Latin_Square()
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
谢谢成功了!我将添加到代码中,对拉丁方执行洗牌。我可以再发一次!