简体   繁体   English

Select 基于幻灯片标签的 Powerpoint 幻灯片并复制到新的演示文稿中

[英]Select Powerpoint slides based on the slide tags and copy into a new presentation

I have a slide deck of about 30 slides which is mix of slides for different areas (Azure, AWS etc.).我有一个包含大约 30 张幻灯片的幻灯片,其中混合了不同领域(Azure、AWS 等)的幻灯片。 My goal is to be able to pull out specific slides into a new presentation based on requirement.我的目标是能够根据要求将特定幻灯片提取到新的演示文稿中。 For example pull out all slides related to Azure.例如,拉出与 Azure 相关的所有幻灯片。 So, for this i have assigned tags to each slide ( https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slide.tags ).因此,为此我为每张幻灯片分配了标签( https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slide.tags )。 Now i need help in using these tags to pull out those slides from the main PowerPoint deck into a new PowerPoint deck.现在我需要帮助来使用这些标签将这些幻灯片从主 PowerPoint 幻灯片中拉出到新的 PowerPoint 幻灯片中。

Code to assign tags:分配标签的代码:

Sub Assign_tags()
ActivePresentation.Slides(7).Tags.Add "pname", "Azure"
ActivePresentation.Slides(8).Tags.Add "pname", "Azure"
ActivePresentation.Slides(9).Tags.Add "pname", "Azure"
ActivePresentation.Slides(10).Tags.Add "pname", "Azure"
ActivePresentation.Slides(11).Tags.Add "pname", "Azure"
ActivePresentation.Slides(12).Tags.Add "pname", "Azure"
ActivePresentation.Slides(13).Tags.Add "pname", "Azure"
ActivePresentation.Slides(14).Tags.Add "pname", "Azure"
ActivePresentation.Slides(15).Tags.Add "pname", "Azure"
ActivePresentation.Slides(16).Tags.Add "pname", "Azure"
ActivePresentation.Slides(17).Tags.Add "pname", "Azure"
ActivePresentation.Slides(18).Tags.Add "pname", "Azure"
ActivePresentation.Slides(19).Tags.Add "pname", "Azure"
ActivePresentation.Slides(20).Tags.Add "pname", "Azure"
ActivePresentation.Slides(21).Tags.Add "pname", "Azure"
ActivePresentation.Slides(22).Tags.Add "pname", "Azure"
ActivePresentation.Slides(23).Tags.Add "pname", "Azure"
ActivePresentation.Slides(24).Tags.Add "pname", "Azure"
ActivePresentation.Slides(25).Tags.Add "pname", "Azure"
ActivePresentation.Slides(26).Tags.Add "pname", "Azure"

ActivePresentation.Slides(27).Tags.Add "pname", "AWS"

ActivePresentation.Slides(28).Tags.Add "pname", "GCP"
End Sub

Code to copy the slides with Azure tag to a new presentation将带有 Azure 标记的幻灯片复制到新演示文稿的代码

    Sub SaveSeparateSlide2()

    Dim curPres As Presentation
    Set curPres = ActivePresentation
    Dim newPres As Presentation
    Set newPres = Presentations.Add

For Each s In curPres.Slides

    If s.Tags("pname") = "Azure" Then

      s.Copy
      newPres.Slides.Paste

    End If

Next

    'change your path and name here:
    newPres.SaveAs "Azure slides.pptx"
    newPres.Close

End Sub

I would advise using a For Loop to assign tags instead of having multiple lines of codes of the same:我建议使用For Loop来分配标签,而不是使用多行相同的代码:

For i = 7 To 26
ActivePresentation.Slides(i).Tags.Add "pname", "Azure"
Next i

Now, we need to pick out the slides which contain the Tag pname with the value azure现在,我们需要选择包含标签pname且值为azure的幻灯片

    Dim slNum() As Integer
    Dim n As Integer
'above are global declarations

    n = -1 'do this in some initialise sub-routine

Sub SelectSlides()
    For Each s In Application.ActivePresentation.Slides
    With s.Tags
        For i = 1 To .Count
          If .Value(i) = "Azure" Then
          n = n + 1
          ReDim Preserve slNum(n)
          slNum(n) = .Parent.SlideIndex 'We now stored the slide number of the slide which contains the tag 
          End If
        Next i
    End With
    Next
End Sub

Instead of duplicating the slide you can also copy and paste that slide in the required index.除了复制幻灯片,您还可以复制该幻灯片并将其粘贴到所需的索引中。

Sub copy()
    ActivePresentation.Slides(i).Copy
    ActivePresentation.Slides.Paste Index:=5
End Sub

If you want to move the slide:如果要移动幻灯片:

Sub move()
    ActivePresentation.Slides(3).MoveTo ToPos:=1
End Sub

Hopefully, this helps you out!希望这可以帮助您!

EDIT: To take the selected slides into a new presentation:编辑:要将选定的幻灯片放入新的演示文稿中:

Dim pptApp As Object
Dim pptPS As Object

Set pptApp = CreateObject("Powerpoint.Application")
Set pptPS = pptApp.Presentations.Add

pptPS.SaveAs "Type folder path here"

For i = 0 To n
ActivePresentation.Slides.Item(i).Copy
pptPS.Item(1).Slides.Paste
Next i

pptPS.Save
pptPS.Close
pptApp.Quit

Set pptPS = Nothing
Set pptApp = Nothing

I haven't tested the above code, I do not think it will work as it is though (a gut feeling).我还没有测试过上面的代码,但我认为它不会按原样工作(直觉)。 Please de-bug it.请调试它。

Option Explicit


Sub Assign_tags()
ActivePresentation.Slides(1).Tags.Add "pname", "Azure"
ActivePresentation.Slides(2).Tags.Add "pname", "AWS"
ActivePresentation.Slides(3).Tags.Add "pname", "Azure"
ActivePresentation.Slides(4).Tags.Add "pname", "GCP"
End Sub

Sub extract_slides()

Dim strTagName As String
Dim strTagValue As String

strTagName = "pname"
strTagValue = "Azure"

Dim currentPresentation As Presentation
Dim newPresentation As Presentation
Dim s As Slide

' Save reference to current presentation
Set currentPresentation = Application.ActivePresentation

' Save reference to current slide
'Set currentSlide = Application.ActiveWindow.View.Slide

' Add new Presentation and save to a reference
Set newPresentation = Application.Presentations.Add

For Each s In currentPresentation.Slides
    If s.Tags(strTagName) = "Azure" Then
         s.Copy
         ' Paste it in new Presentation
        newPresentation.Slides.Paste
    End If
Next

newPresentation.SaveAs (currentPresentation.Path & "\" & strTagValue & "_Extract.pptx")

End Sub

暂无
暂无

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

相关问题 如何根据特定的幻灯片输入将幻灯片从现有演示文稿复制到新演示文稿? - How to copy the slides from existing presentation to new presentation based on the specific slide input? Powerpoint幻灯片:如何将我在一张幻灯片上的组合框和文本框控件复制到另一张相同演示文稿的幻灯片上? - Powerpoint slides: how to copy my combobox and textbox controls on one slide to a another slide, same presentation? 将基于特定单词的幻灯片复制到新的演示文稿 - Copy slide based on specific words to new presentation Excel vba将幻灯片复制到现有的PowerPoint演示文稿 - Excel vba to copy slides to an existing powerpoint presentation 在 PowerPoint 演示文稿中复制幻灯片 - Duplicating a slide in PowerPoint presentation 在另一个 Powerpoint 演示文稿中嵌入来自其他 Powerpoint 演示文稿的幻灯片的链接副本 - Embed a linked copy of a slide from other Powerpoint presentation in another Powerpoint presentation 在VBA powerpoint中如何将新幻灯片添加到空的演示文稿中 - in VBA powerpoint How to add a new slide to an empty presentation 从Excel调用宏以打开PowerPoint演示文稿,插入幻灯片以及将范围复制到幻灯片有时会起作用,但会出错 - Macro called from Excel to Open a PowerPoint Presentation, Insert a Slide, and Copy Range to Slide works sometimes, errors others 如何使用 VBA 将 powerpoint 部分复制到新的演示文稿 - How to copy powerpoint sections to a new presentation using VBA 在PowerPoint中选择一系列幻灯片 - Select a range of slides in PowerPoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM