我正在尝试在调用此函数时将选定的幻灯片导出为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中的超链接):
Sub Main()
'Hide all slides
For i = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(i).SlideShowTransition.Hidden = msoTrue
Next i
'Show your slides (for example: slide 2 + 4)
ActivePresentation.Slides(2).SlideShowTransition.Hidden = msoFalse
ActivePresentation.Slides(4).SlideShowTransition.Hidden = msoFalse
'Save location
Dim filePath As String
filePath = "C:\Users\YOUR_NAME\Desktop\fileName.pdf"
ActivePresentation.SaveAs filePath, ppSaveAsPDF
'Show all slides again
For i = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(i).SlideShowTransition.Hidden = msoFalse
Next i
End Sub