2016-07-18 6 views
1

이 기능을 호출 할 때 선택한 슬라이드를 pdf로 내보내려고합니다.파워 포인트 vba 특정 슬라이드를 PDF로 내보내기

이 코드는 훌륭하게 작동하지만 전체 슬라이드 쇼를 PDF로 제공합니다.

Sub Export_to_PDF() 
    ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & "ExportedFile" & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint 
End Sub 

슬라이드 번호 나 일련의 슬라이드를 PDF로 내보낼 수 있도록 위 코드를 어떻게 변경할 수 있습니까? 슬라이드 쇼보기에서이 코드를 실행할 수 있어야합니다.

감사합니다.

답변

1

좋아, 그래서 몇 달 간의 검색을 거쳐 결국 답을 찾았으니 여기에서 공유하고 싶다고 생각했다. 대부분의 코드는 그물에서 발견되는 무작위적인 부분과 내 자신의 짧은 코드를 통해 제공됩니다.

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 
관련 문제