A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
If you copy a code from one file to an other you have to a) set the same references as in the original file or b) use late binding code, as shown below.
Note:
I've commented out one line, because the variable "Filename" is not set in that code.
Andreas.
Sub PrintLinkedPowerpoints_FINAL()
Dim pptApp As Object 'PowerPoint.Application
Dim pptPres As Object 'PowerPoint.Presentation
Dim nameRng As Range
Dim i As Long
Dim groupName, pdf_file
Const ppSaveAsPDF = 32
Set pptApp = GetObject(, "PowerPoint.Application")
Set pptPres = pptApp.Presentations("Presentation1.pptx")
Set nameRng = Excel.Application.Workbooks("MortalityGraphs_RATES_forReport_READY.FOR.CHECK.xlsx").Sheets("All Drug Overdose -Age-Adj Rate").Range("$A$2:$F$7")
For i = 1 To nameRng.Rows.Count
groupName = nameRng.Cells(i, 1).Value
Excel.Application.Workbooks("MortalityGraphs_RATES_forReport_READY.FOR.CHECK.xls").Sheets("All Drug Overdose -Age-Adj Rate").Range("A9") = groupName
pdf_file = ThisWorkbook.Path & "" & groupName & " MacroTest1.pdf"
pptPres.UpdateLinks
pptApp.Activate
'!! Filename not defined !!
'pptPres.SaveCopyAs Filename:=Filename
pptPres.SaveAs Filename:=pdf_file, FileFormat:=ppSaveAsPDF
Next
End Sub