-
Aug 15th, 2019, 10:03 AM
#1
Thread Starter
Member
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!
-
Aug 16th, 2019, 01:58 AM
#2
Addicted Member
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
-
Aug 16th, 2019, 03:08 AM
#3
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
-
Aug 17th, 2019, 06:14 PM
#4
Thread Starter
Member
Re: Open Powerpoint File and Export to PDF
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!
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|