I am trying to copy a range of data from excel into an existing powerpoint slide then save that slide with a specific name (that I extract from an excel file) as a pdf . This process is going to be repeated. I have figured out how to copy the data into the powerpoint slide but am having issues trying to get the slide to save as a pdf - get object error. I have no idea what is wrong with the line of code that tries to save a pdf (in red text) - I get object error. Below is the macro I created:
Sub CreatePDFfiles_4()
Dim PPapp As Object
Dim PPPres As Object
Dim first_file As Boolean
Dim investorname As String
Dim invpath As String
Dim cor_file_name As String
Dim file1 As String
Dim DestinationPPT As String
Dim print_data As String
'Getting worksheet name where excel data will be extracted from and extracting path and filename for pdf file
Sheets("printing").Select
Range("g2").Select
file1 = ActiveCell.Value
Range("g3").Select
invpath = ActiveCell.Value
Range("g8").Select
investorname = ActiveCell.Value
Range("i8").Select
cor_file_name = ActiveCell.Value
DestinationPPT = "C:\Users\Celia Dieterich\Documents\Bloomfield\Investment Model\printing macro\template.pptx"
' Opening powerpoint
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
PPPres.Slides(1).Shapes.Paste
'Save as pdf
ActivePresentation.ExportAsFixedFormat invpath & cor_file_name & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint
' Tried this and didn't work as well
'ActivePresentation.ExportAsFixedFormat path:=invpath & cor_file_name & ".pdf", FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection
PPapp.Quit
Set PPapp = Nothing
End If
Workbooks("Printing Investor sheets.xlsm").Activate
Sheets("printing").Select
ActiveCell.Offset(1, -1).Select
investorname = ActiveCell.Value
ActiveCell.Offset(0, 2).Select
cor_file_name = ActiveCell.Value
Wend
End Sub