Save pptx as pdf via excel

I am trying to convert all pptx files to PDF file transfer path.

my code:

Sub pptxtopdf()

    Dim ppt As Object
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object


    Dim i As Integer
    On Error Resume Next

    Set ppt = GetObject(, "PowerPoint.Application")
    If ppt Is Nothing Then
    Set ppt = CreateObject("PowerPoint.Application")
    End If
    On Error GoTo 0


    'Create an instance of the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Get the folder object
    Set objFolder = objFSO.GetFolder("P:\Operations\Data & Deliverables\Projects\Amica\presentation_workspace\1_ spring 2015\Presentations\Volvo")
    i = 1
    'loops through each file in the directory 
    For Each objFile In objFolder.Files

        Set WDReport = ppt.Presentations.Open(objFile.Path)

        Dim FileName2 As String
        FileName2 = Replace(objFile.Path, "pptx", "pdf")

        'WDReport.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF
        WDReport.SaveAs FileName2, ppSaveAsPDF

        WDReport.Close
        ppt.Quit

        Set ppt = Nothing
        Set WDReport = Nothing


        i = i + 1
    Next objFile


End Sub

      

error msg

Presentation.SaveAs :  Invalid enumeration value. 

      

Can't see what I am doing wrong?

same problem as here but the solution didn't work for me - Excel macro to save pptx as pdf; error with code

+3


source to share


1 answer


You are late for binding PowerPoint.Application

, so its enumeration values ​​are not displayed or available in the global VBA namespace.

Since you haven't added option explicit

to warn you about undeclared variables, using undeclared ppSaveAsPDF

doesn't throw an error, but it doesn't matter.

Add to



const ppSaveAsPDF as long = 32

      

Top of the module to provide the expected value SaveAs

.

+5


source







All Articles