简体   繁体   English

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

[英]How to copy the slides from existing presentation to new presentation based on the specific slide input?

This is my first task on PPT Macros.这是我在 PPT 宏上的第一个任务。 I have the code which can copy the selected slides and pastes into a new presentation, it is very time taking especially when selecting the slides which are not in order eg(1,2,5,8,9).我有代码可以将选定的幻灯片复制并粘贴到新的演示文稿中,特别是在选择不按顺序的幻灯片(例如(1,2,5,8,9)时),这非常耗时。 I am looking for a code where we can give give specific slide numbers in the code, just like above (1,2,5,8,9) and I should be able to change when I have to copy different set of slides.我正在寻找一个代码,我们可以在代码中给出特定的幻灯片编号,就像上面的 (1,2,5,8,9) 一样,当我必须复制不同的幻灯片集时,我应该能够进行更改。 Please look the current below code and suggest accordingly.请查看当前的以下代码并提出相应建议。

'Set variable to Active Presentation
 Set OldPPT = ActivePresentation

'Set variable equal to only selected slides in Active Presentation
 Set Selected_slds = ActiveWindow.Selection.SlideRange

'Sort Selected slides via SlideIndex
'Fill an array with SlideIndex numbers
 ReDim myArray(1 To Selected_slds.Count)
  For y = LBound(myArray) To UBound(myArray)
    myArray(y) = Selected_slds(y).SlideIndex
  Next y

 'Sort SlideIndex array
  Do
  SortTest = False
  For y = LBound(myArray) To UBound(myArray) - 1
    If myArray(y) > myArray(y + 1) Then
      Swap = myArray(y)
      myArray(y) = myArray(y + 1)
      myArray(y + 1) = Swap
      SortTest = True
    End If
  Next y
  Loop Until Not SortTest

 'Set variable equal to only selected slides in Active Presentation (in 
 numerical order)
 Set Selected_slds = OldPPT.Slides.Range(myArray)

'Create a brand new PowerPoint presentation
 Set NewPPT = Presentations.Add

'Align Page Setup
 NewPPT.PageSetup.SlideHeight = OldPPT.PageSetup.SlideHeight
 NewPPT.PageSetup.SlideOrientation = OldPPT.PageSetup.SlideOrientation
 NewPPT.PageSetup.SlideSize = OldPPT.PageSetup.SlideSize
 NewPPT.PageSetup.SlideWidth = OldPPT.PageSetup.SlideWidth

'Loop through slides in SlideRange
 For x = 1 To Selected_slds.Count

'Set variable to a specific slide
Set Old_sld = Selected_slds(x)

'Copy Old Slide
y = Old_sld.SlideIndex
Old_sld.Copy

'Paste Slide in new PowerPoint
NewPPT.Slides.Paste
Set New_sld = Application.ActiveWindow.View.Slide

'Bring over slides design
 New_sld.Design = Old_sld.Design

'Bring over slides custom color formatting
 New_sld.ColorScheme = Old_sld.ColorScheme

'Bring over whether or not slide follows Master Slide Layout (True/False)
 New_sld.FollowMasterBackground = Old_sld.FollowMasterBackground

Next x

End Sub

This should replace your 'Loop through slides in SlideRange to the end.这应该将您的“循环播放 SlideRange 中的幻灯片”替换为最后。 You should be able to delete all the selected slide code.您应该能够删除所有选定的幻灯片代码。 This just asks the user to input all the slide numbers needed to copy in a comma separated list.这只是要求用户在逗号分隔列表中输入复制所需的所有幻灯片编号。

 Sub testr()


 Dim SlideArray As Variant
'Set variable to Active Presentation
 Set OldPPT = ActivePresentation
'Create a brand new PowerPoint presentation
 Set NewPPT = Presentations.Add

    InSlides = InputBox("List the slide numbers separated by commas:", "Slides", 2)

    SlideArray = Split(InSlides, ",")

For x = 0 To UBound(SlideArray)
        sld = CInt(SlideArray(x))

'Set variable to a specific slide
Set Old_sld = OldPPT.Slides(sld)

'Copy Old Slide
y = Old_sld.SlideIndex
Old_sld.Copy

'Paste Slide in new PowerPoint
NewPPT.Slides.Paste
Set New_sld = Application.ActiveWindow.View.Slide

'Bring over slides design
 New_sld.Design = Old_sld.Design

'Bring over slides custom color formatting
 New_sld.ColorScheme = Old_sld.ColorScheme

'Bring over whether or not slide follows Master Slide Layout (True/False)
 New_sld.FollowMasterBackground = Old_sld.FollowMasterBackground

Next x
 End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel vba将幻灯片复制到现有的PowerPoint演示文稿 - Excel vba to copy slides to an existing powerpoint presentation 如何在演示文稿中循环幻灯片,将新的Excel范围粘贴到每张幻灯片中的表格中 - How to loop through slides in a presentation, pasting a new Excel range into a table in each slide 从Excel中的不同工作表中复制表并将其粘贴到现有演示文稿中 - Copy tables from different worksheet in excel and paste it in existing presentation 从Excel调用宏以打开PowerPoint演示文稿,插入幻灯片以及将范围复制到幻灯片有时会起作用,但会出错 - Macro called from Excel to Open a PowerPoint Presentation, Insert a Slide, and Copy Range to Slide works sometimes, errors others 在 PowerPoint 演示文稿中复制幻灯片 - Duplicating a slide in PowerPoint presentation 通过 VBA 获取 PPT 演示文稿的活动幻灯片(但来自 Excel !!) - Getting the Active Slide of a PPT Presentation via VBA (but from Excel!!) 从ppt演示文稿中选择某些幻灯片并粘贴excel图表 - select certain slide from ppt presentation and paste excel chart VBA 将多个 Powerpoint 演示文稿幻灯片保存为 JPG - VBA Save Multiple Powerpoint presentation slides as JPG 无法使用 VBA 从 Excel 打开现有的 PowerPoint 演示文稿 (2016) - Unable to open an existing PowerPoint Presentation (2016) from Excel using VBA 使用VBA从Excel复制到打开的Powerpoint演示文稿 - Using VBA to copy from Excel to an open Powerpoint presentation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM