PDF

2017-09-18 2 views
0

에 PPT 파일을 변환 I 통합 문서에 저장된 파워 포인트 파일을 열고 다음이 잘 작동 아래의 코드PDF

Set PApp = CreateObject("PowerPoint.Application") 
PApp.Visible = True 
Pth = ThisWorkbook.Path 
ErrorPopUp = True 

Dim TsyTemplate As Object 

Set TsyTemplate = ThisWorkbook.Sheets("Report Templates").OLEObjects(“Report 1”) 
TsyTemplate.Copy 
Sheets("Version Control").Paste 
Set TsyTemplate = ThisWorkbook.Sheets("Book 1").OLEObjects(1) 
TsyTemplate.Verb Verb:=xlOpen 

Set TsyTemplate = Nothing 

Set PPres = PApp.ActivePresentation 

를 사용하여 수정하는 매크로 그러나 나는 다음을 변환하는 몇 가지 코드를 추가 할 수 있습니다 PowerPoint 파일을 PDF 파일로 엽니 다. 난 그냥 어딘가에 저장하지 않고 변환하는 것을 선호하지만

PDFName = ActiveWorkbook.Path & "/test.pdf" 
PPres.ExportAsFixedFormat Path:=PDFName,  FixedFormatType:=ppFixedFormatTypePDF,  RangeType:=ppPrintSelection 

이 같은 있지만 작동하지 않는 PDF 파일로 저장하는 코드 아래에 그가 사용하고, 그래서 나는이 가능하다 생각하지 않는다 I "유형이 일치하지 않습니다"라는 오류 메시지가 표시됩니다.

내가 뭘 잘못하고 있는지에 대한 제안이있는 사람이 있습니까?

감사

전체 코드 :

Global PApp As Object 
Global PPres As Object 
Global PPTFileName As String 
Global ppFixedFormatTypePDF As Long 
Global ppPrintSelection As Long 

하위 Test_Printing_To_PDF()

Set PApp = CreateObject("PowerPoint.Application") 
PApp.Visible = True 
Pth = ThisWorkbook.Path 
ErrorPopUp = True 

Dim TsyTemplate As Object 

Set TsyTemplate = ThisWorkbook.Sheets("Report Templates").OLEObjects("Report 1") 
TsyTemplate.Copy 
Sheets("Version Control").Paste 

Set TsyTemplate = ThisWorkbook.Sheets("Version Control").OLEObjects(1) 

TsyTemplate.Verb Verb:=xlOpen 

Set TsyTemplate = Nothing 

Set PPres = PApp.ActivePresentation 


PPres.Slides(1).Shapes("Presentation_Title").TextFrame.TextRange.Text = "Test printing code" 


ppFixedFormatTypePDF = 2 
ppPrintSelection = 2 


PDFName = ActiveWorkbook.Path & "/test.pdf" 
PPres.ExportAsFixedFormat Path:=PDFName, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection 

최종 하위

+0

어디에서 변수를 DIM하고 DIMmed PPres를 사용합니까? Alsol ppFixedFormatTypePDF 및 ppPrintSelection은 PPT 상수이며 Excel에서는 정의되지 않으므로 정의해야합니다 (Longs = 2로 모두) –

+0

안녕하세요. 변수는 모듈의 다른 곳에 정의됩니다. Ppres는 객체로 정의됩니다. 나는 다른 2를 정의하지 않았으므로 (longs와 = 2와 같이) 그런데 형식 불일치 메시지가 나타납니다. –

+0

오류가 발생한 줄은 무엇입니까? FWIW, 코드의 PDF 내보내기 부분은 PPT 내에서 실행 한 사실에 맞게 몇 가지 모드로 PowerPoint 내에서 예상대로 작동합니다. 하지만 액티브 프리젠 테이션에 PPres를 설정하고 있는데 액티브 프레젠테이션이 있습니까? 슬라이드를 열지 않았거나 기본 프레젠테이션에 슬라이드를 추가하지 않았으므로 PDF로 정확히 내보내려고하십니까? –

답변

0

내가 여기이 시도 할 수 있도록 내가 엑셀 ​​코드의 일부를 제거 ; PPT에서 PDF 내보내기와 관련이없는 것 같으므로 아무런 차이가 없어야합니다. 코멘트가있는 새로운 (작업 중) 코드 :

Option Explicit 

Global PApp As Object 
Global PPres As Object 
Global PPTFileName As String 
Global ppFixedFormatTypePDF As Long 
Global ppPrintSelection As Long 

Const ppSaveAsPDF As Long = 32 

Sub Test_Printing_To_PDF() 

' Always include Option Explicit and DIM all variables 
Dim Pth As String 
Dim ErrorPopUp As Boolean 
Dim PDFName As String 

Set PApp = CreateObject("PowerPoint.Application") 
PApp.Visible = True 
Pth = ThisWorkbook.Path 
ErrorPopUp = True 

' Just invoking PowerPoint doesn't necessarily create a presentation. 
' You need to add one (or open an existing one) 
Set PPres = PApp.presentations.Add 

' And creating a new presentation doesn't necessarily add slides so: 
PPres.slides.Add 1, 1 

' Unless you've opened a presentation that happens to have a shape named 
' Presentation_Title on the first slide, this will fail: 
'PPres.slides(1).Shapes("Presentation_Title").TextFrame.TextRange.Text = "Test printing code" 
' So I've changed it to this: 
PPres.slides(1).Shapes(1).TextFrame.TextRange.Text = "Test printing code" 

'/isn't a valid character: 
'PDFName = ActiveWorkbook.Path & "/test.pdf" 
' so I changed it to this: 
PDFName = ActiveWorkbook.Path & "\test.pdf" 

' And there are all sorts of reports all over the net about 
' the Export routine being buggy. Substitute this and it works: 
PPres.SaveAs PDFName, ppSaveAsPDF 


End Sub 
+0

감사합니다. –