Reputation: 173
I am trying to simply open a powerpoint and then SaveAs with a new name.
I get "compile error: Method or data member not found"
Public Sub OpenPPTfinalOpp()
Dim templatePath As String
Set PPT = New PowerPoint.Application
templatePath = ThisWorkbook.Sheets("Automation").Range("D20")
'templatePath = "C:\Users\[userName]\Desktop\test\Weekly Pack Update - Template.pptx"
PPT.Visible = False
Set PPT_pres = PPT.Presentations.Open(Filename:=templatePath)
Set PPT_pres = PPT.Presentations.SaveAs(Filename:="C:\Users\[userName]\Desktop\test\Weekly Pack Update - Final.pptx")
End Sub
The code runs without the SaveAs line, ideally i could run this without opening the the powerpoint as this is just the first step before attaching it to an email.
Thanks
Upvotes: 0
Views: 509
Reputation: 7951
Upgraded from a Comment on the question:
To do this without opening Powerpoint, for any filetype: FileCopy
ThisWorkbook.Sheets("Automation").Range("D20"), "C:\Users\[userName]\Desktop\test\Weekly Pack Update - Final.pptx"
To do this slightly more safely:
Public Function SafeCopy(Source As String, Destination As String) As Boolean
SafeCopy = False
'Source does not exist
If Len(Dir(Source)) < 2 Then Exit Function
'Clear destination file if it already exists
If Len(Dir(Destination)) > 1 Then
Kill Destination
'Cannot clear destination
If Len(Dir(Destination)) > 1 Then Exit Function
End If
'Do the actual copy
FileCopy Source, Destination
'Report on success/failure
SaveCopy = (Len(Dir(Destination)) > 1)
End Function
Upvotes: 1