Save powerpoint presentation as as a pdf in vba

2019-08-22 16:16发布

问题:

I have looked at a lot of answers to this question but can't figure out what I have done wrong. I am trying to create a pdf file. I get my data from an excel file and copy it into powerpoint. I then try to save as pdf but it keeps giving me an error (object required) at the saving pdf section of the macro (see below). I tried changing it multiple times but still can't get it to work. Have attached code below. After I fix this problem, I need to be able to change the size of the object I pasted in - how do I do that.

Sub CreatePDFfiles_4()


Dim PPapp As Object
Dim PPPres As Object
Dim first_file As Boolean
Dim investorname As String
Dim path As String


Sheets("printing").Select
Range("g2").Select
file1 = ActiveCell.Value
Range("g3").Select
path = ActiveCell.Value
Range("g8").Select
investorname = ActiveCell.Value
Range("i8").Select
cor_file_name = ActiveCell.Value
DestinationPPT = "C:\Users\name\Documents\company\Investment Model\printing macro\template.pptx"


While investorname <> "end"
    ActiveCell.Offset(0, -1).Select
    print_data = ActiveCell.Value
    If print_data = "Yes" Then

        ' Initialize PowerPoint Object Library
        Set PPapp = CreateObject("Powerpoint.Application")
        PPapp.Visible = True

        ' Open presentation
        Set PPPres = PPapp.Presentations.Open(DestinationPPT)

        'Copy excel file data
        Windows(file1).Activate
        Sheets(investorname).Select
        Range("b1:r46").Select
        Selection.Copy

        'Paste into existing powerpoint template slide that is open
        PPPres.slides(1).Shapes.Paste

        'Save as pdf
        PPPres.ExportAsFixedFormat ActivePresentation.path & "\" & cor_file_name & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint



        PPapp.Quit
        Set PPapp = Nothing