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!
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
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
Re: Open Powerpoint File and Export to PDF
Quote:
Originally Posted by
westconn1
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!