Results 1 to 4 of 4

Thread: Open Powerpoint File and Export to PDF

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2018
    Posts
    59

    Open Powerpoint File and Export to PDF

    Hi,

    I need to open a Powerpoint File and Export to PDF with no Powerpoint Window.

    This function bellow works perfectly:

    Code:
    Public Function PowerPointToPDF(ByVal xSourceFile As String, _
                                    ByVal xDestinationFile As String) As Boolean
        On Error Resume Next
        Dim wObj As Object
        Set wObj = CreateObject("Powerpoint.Application")
        If (Err = 0) Then
            wObj.Presentations.Open FileName:=xSourceFile, ReadOnly:=True, WithWindow:=True
            wObj.ActivePresentation.SaveAs FileName:=xDestinationFile, FileFormat:=32
            wObj.ActivePresentation.Close
            wObj.Quit
            PowerPointToPDF = (Err = 0)
        End If
        Set wObj = Nothing
        On Error GoTo 0
    End Function
    But If I will change WithWindow:=True to WithWindow:=False, this function returns an error indicates that is no have an ActivePresentation.

    In short, I need a function to convert Powerpoint files to PDF without the Powerpoint application window being visible.

    Can you help me?

    With best regards!

  2. #2
    Addicted Member gilman's Avatar
    Join Date
    Jan 2017
    Location
    Bilbao
    Posts
    176

    Re: Open Powerpoint File and Export to PDF

    Logically, if there is not Window, there is not ActivePresentation, so you must indicate the Presentation you want save, how you are creating the PowerPoint application there is only one Presentation, and this code would must work:
    Code:
    Public Function PowerPointToPDF(ByVal xSourceFile As String, _
                                    ByVal xDestinationFile As String) As Boolean
        On Error Resume Next
        Dim wObj As Object
        Set wObj = CreateObject("Powerpoint.Application")
        If (Err = 0) Then
            wObj.Presentations.Open FileName:=xSourceFile, ReadOnly:=True, WithWindow:=False
            wObj.Presentations(1).SaveAs FileName:=xDestinationFile, FileFormat:=32
            wObj.Presentations(1).Close
            wObj.Quit
            PowerPointToPDF = (Err = 0)
        End If
        Set wObj = Nothing
        On Error GoTo 0
    End Function

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Open Powerpoint File and Export to PDF

    maybe try like
    Code:
       Set objpresentation = wObj.Presentations.Open FileName:=xSourceFile, ReadOnly:=True, WithWindow:=False
            objpresentation.SaveAs FileName:=xDestinationFile, FileFormat:=32
            objpresentation.Close
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2018
    Posts
    59

    Re: Open Powerpoint File and Export to PDF

    Quote Originally Posted by westconn1 View Post
    maybe try like
    Code:
       Set objpresentation = wObj.Presentations.Open FileName:=xSourceFile, ReadOnly:=True, WithWindow:=False
            objpresentation.SaveAs FileName:=xDestinationFile, FileFormat:=32
            objpresentation.Close
    It's work perfectly!

    I am aprecciate your help!

    With best regards!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width