简体   繁体   中英

VBA open powerpoint save with new name

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM