首页 > 解决方案 > VBA PowerPoint - 如何选择特定幻灯片或按部分选择并导出到 MP4?

问题描述

例如:导出幻灯片编号 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

标签: vbapowerpoint

解决方案


我从未将 powerpoint 演示文稿导出到 mp4,但在我拥有的 powerpoint 2013 版本中,您似乎可以在Save As时创建 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

推荐阅读