Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
powerpoint vba将特定幻灯片导出为pdf_Vba_Pdf_Powerpoint_Export To Pdf - Fatal编程技术网

powerpoint vba将特定幻灯片导出为pdf

powerpoint vba将特定幻灯片导出为pdf,vba,pdf,powerpoint,export-to-pdf,Vba,Pdf,Powerpoint,Export To Pdf,调用此函数时,我正在尝试将所选幻灯片导出为pdf 这段代码工作得非常出色,但它以PDF格式显示了整个幻灯片 Sub Export_to_PDF() ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & "ExportedFile" & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint End Sub 如何更改上述代码

调用此函数时,我正在尝试将所选幻灯片导出为pdf

这段代码工作得非常出色,但它以PDF格式显示了整个幻灯片

Sub Export_to_PDF()
    ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & "ExportedFile" & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint
End Sub
如何更改上述代码,以便指定要导出为PDF的幻灯片编号或幻灯片系列。我需要这个代码能够从幻灯片视图运行


非常感谢。

好的,经过几个月的搜索,我终于找到了答案,我想我会在这里分享它,再加上一些基于我努力实现的附加信息。大多数代码都是由网络上的随机部分和我自己的一些劣质代码提供的

Sub Generate_PDF_Cert()
'This function saves the last slide as a PDF file with a time stamp and the users name who completed the induction.

timestamp = Now()

Dim PR As PrintRange
Dim lngLast As Long
Dim savePath As String
Dim PrintPDF As Integer


'Location of saved file
savePath = Environ("USERPROFILE") & "\Desktop\Induction\Certificates\" & Format(timestamp, "yyyymmdd-hhnn") & "_" & FirstNameX & "_" & LastNameX & ".pdf"

lngLast = ActivePresentation.Slides.Count

With ActivePresentation.PrintOptions
    .Ranges.ClearAll ' always do this
    Set PR = .Ranges.Add(Start:=lngLast, End:=lngLast)
End With

ActivePresentation.ExportAsFixedFormat _
Path:=savePath, _
FixedFormatType:=ppFixedFormatTypePDF, _
PrintRange:=PR, _
Intent:=ppFixedFormatIntentScreen, _
FrameSlides:=msoTrue, _
RangeType:=ppPrintSlideRange

'Prompt user of file location and option to print.
PrintPDF = MsgBox("A PDF file of this certificate has been saved to: " & vbCrLf & savePath & vbCrLf & vbCrLf & "Would you like to print a copy also?", vbYesNo, "PDF File Created")
If PrintPDF = 6 Then Call Print_Active_Slide


End Sub
因此,PDF创建得又好又简单。它基本上是将放映的最后一张幻灯片导出为PDF格式。这可以更改为特定幻灯片或幻灯片范围。然后,还可以使用以下功能打印所选幻灯片:

Sub Print_Active_Slide()
' This code determines what slide is currently visible in the
' slide show and then it clears the print range and prints out the
' current slide.


' Declare lSldNum as a long integer.
Dim lSldNum As Long

' Assign lSldNum to the current slide number.
lSldNum = SlideShowWindows(1).View.Slide.SlideNumber

' Set the print options for the active presentation.
With ActivePresentation.PrintOptions

' Set RangeType to print a slide range.
 .RangeType = ppPrintSlideRange

 ' Delete old print range settings.
 .Ranges.ClearAll

 ' Set Ranges to the new range for the current slide.
 .Ranges.Add lSldNum, lSldNum
End With

' Using the current print settings print the slide to the default
' printer.
ActivePresentation.PrintOut

MsgBox "The file has been sent to the default printer", vbOKOnly, "Print Job Sent"

End Sub

谢谢,我也遇到了同样的问题,这是我的解决方案(以pdf格式保存超链接):


您还可以使用以下方法将所选幻灯片保存到PDF文件:

Sub Test()

    'select slides
    ActivePresentation.Slides.Range(Array(1, 2, 4, 6, 9, 11)).Select
    'save selected slides to a PDF file
    ActivePresentation.ExportAsFixedFormat Path:="C:\Path\xxx.pdf", _
        FixedFormatType:=ppFixedFormatTypePDF, _
        Intent:=ppFixedFormatIntentPrint, _
        OutputType:=ppPrintOutputSlides, _
        RangeType:=ppPrintSelection

End Sub
但是,如果从Excel VBA调用此函数,则可能无法获取所选幻灯片。因此,如果从Powerpoint外部调用此功能,请确保先激活幻灯片预览窗格,如下所示:

    Set pptApp = ActivePresentation.Parent 'Powerpoint Application
    pptApp.ActiveWindow.Panes(1).Activate 'You can skip this if you're already in Powerpoint

回答得很好。比我一起废弃的代码更简单。我想从现在起我会用这个。谢谢你的新信息。
    Set pptApp = ActivePresentation.Parent 'Powerpoint Application
    pptApp.ActiveWindow.Panes(1).Activate 'You can skip this if you're already in Powerpoint