Most OLE automation code looks pretty much the same. Here's a simple routine:
Public Function PrintPowerPoint(ByVal strPath As String) As Boolean
On Error GoTo ErrHandler
Dim ppt As PowerPoint.Application
Dim pres As PowerPoint.Presentation
Dim lngCtr As Long
' Create the app.
Set ppt = New PowerPoint.Application
' Open the presentation.
Set pres = ppt.Presentations.Open(strPath, True, True, False)
' print it.
pres.PrintOut From:=1, To:=1, Copies:=1
' set status text.
SysCmd acSysCmdSetStatus, "Printing " & pres.Name & ", please wait..."
' allow time for print.
While lngCtr < 10000
lngCtr = lngCtr + 1
DoEvents
Wend
' close the presentation.
pres.Close
' shut down the app.
ppt.Quit
' Success
PrintPowerPoint = True
ExitHere:
' dereference
Set pres = Nothing
Set ppt = Nothing
Exit Function
ErrHandler:
Debug.Print Err & " - " & Err.Description
Resume ExitHere
End Function
The .PrintOut method can be used without any arguments to print the entire presentation.
Don't forget to reference the Powerpoint library by clicking 'Tools -> References' from within the VB editor and checking 'Microsoft PowerPoint 9.0 Object Library' or whatever version you're using.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.