【问题标题】:VBA PowerPoint - How to select specific slides or by section and export to MP4?VBA PowerPoint - 如何选择特定幻灯片或按部分选择并导出到 MP4?
【发布时间】:2020-12-18 23:01:09
【问题描述】:

例如:导出幻灯片编号 30 到 80(导出为 mp4)。 一些宏? 或者:只导出一个部分。

我找到了一个按部分导出幻灯片的宏,但它是 png 格式,当我切换到 mp4 时它不起作用。 (罗德里戈·莫拉斯宏)。

Sub Test_Export()                                                          
                                                                           
Dim sld As Slide
i = 1
                                                                
DesiredSection = SectionIndexOf("Test")
                                                                           
For Each sld In ActivePresentation.Slides
                                                                            
If sld.sectionIndex = DesiredSection Then
   ActivePresentation.Slides(i).Export filenamepng & "TEST" & i & ".png", "PNG"
End If
                                                                             
i = i + 1
                                                                          
Next
                                                                           
                                                                           
End Sub
                                                                      
Function SectionIndexOf(sSectionName As String) As Long
    Dim x As Long
    With ActivePresentation.SectionProperties
        For x = 1 To .Count
            If .Name(x) = sSectionName Then
                SectionIndexOf = x
            End If
        Next
    End With                                                                   
End Function

用户(Albert Floor)可以使用此宏将选定的幻灯片导出为 PDF

Private Sub CommandButton4_Click()
Dim myInput As String
Dim savePath As String\

'Name of Student
myInput = ActivePresentation.Slides(1).Shapes("TextBox2").OLEFormat.Object.Text\

'Location of saved file
savePath = ActivePresentation.Path & "\" & myInput & " Antwoorden Virtueel Lab" & ".pdf"  \\\\

'Select path student took
If ActivePresentation.Slides(9).Shapes("TextBox1").OLEFormat.Object.Text = "PRARDT" Then

'Change view
ActivePresentation.SlideShowWindow.View.Exit

'Prevents error 
ActiveWindow.Panes(1).Activate

'Select specific slides
ActivePresentation.Slides.Range(Array(9, 11, 15)).Select

'save selected slides as PDF
ActivePresentation.ExportAsFixedFormat Path:=savePath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection

MsgBox "file saved"

Else
MsgBox "wont work"

End If

End Sub

【问题讨论】:

  • 有什么原因你不能复制幻灯片,删除你不想要的幻灯片,然后用OBS或类似的方式录制?
  • 您能否详细说明您遇到的问题以及您希望宏能做什么?
  • 看起来你是新来的。请阅读本指南,了解如何提出可以得到良好答案的问题:stackoverflow.com/help/how-to-ask
  • @Beefster 关于删除幻灯片,我有很多幻灯片和视频/图像,所以当我尝试删除时,我必须等待很长时间,而且 PowerPoint 经常停止工作,我不得不关闭它。我用OBS录制,但是我做了大量的工作,全天的录制时间需要我很长时间。出于这个原因,我在 Sandboxie 中打开了几个 powerpoints 以同时导出多个视频。我之所以采用这种方式是因为 PowerPoint 甚至无法持续使用我 40% 的硬件,我已经向 Microsoft 支持寻求帮助并执行了许多教程,但它没有奏效。
  • @Marcucciboy2 我在导出大量 mp4 时遇到问题。尝试删除多张幻灯片时需要很长时间,有时会崩溃,因为我有很多带有视频/图像的幻灯片。我希望宏能让我将特定幻灯片导出到 mp4 以解决所有这些问题。例如:导出幻灯片编号 30 到 80(导出为 mp4)。

标签: vba powerpoint


【解决方案1】:

我从未将 powerpoint 演示文稿导出到 mp4,但在我拥有的 powerpoint 2013 版本中,当您另存为时,您似乎能够创建一个 mp4。

另存为荣誉隐藏幻灯片。所以一些简单的代码来隐藏幻灯片然后保存为作品,这里是一些示例代码。在这个例子中,我隐藏了第五张之后的所有幻灯片。

Public Sub Savetomp4()
    Dim mySlides As slides
    Set mySlides = ActivePresentation.slides
    Dim aSlide As Slide
    
    ' Hide some slides
    For i = 0 To mySlides.Count - 1
       If i > 5 Then
           Set aSlide = mySlides.Item(i)
           aSlide.SlideShowTransition.Hidden = msoTrue
       End If
    Next i
    
    ' Save as mp4
    ActivePresentation.SaveAs "c:\temp\test.mp4", ppSaveAsMP4
    Debug.Print "Done!"
End Sub

【讨论】:

  • 它继续保存隐藏的幻灯片:/
  • 我再次测试它并且它工作,加载栏似乎需要很长时间,导出在达到 100% 之前完成,作为一个视觉错误。它完美地工作,虽然它在撤消幻灯片的隐藏时遇到了问题,因为它们会使 PC 崩溃。出于这个原因,我需要一个允许我只导出选定幻灯片或按部分导出的宏,这样我就不必使用 control + z,避免崩溃。但是非常感谢您的帮助。
  • 您是否尝试过调整代码以取消隐藏您隐藏的幻灯片?所以你不需要与任何用户界面交互?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多