Printing specific PowerPoint slides using Excel button

kiwicanta7

New Member
Joined
May 3, 2021
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
Hello!

So I'm trying to add a button to my Excel document that I can hit to print off specific slides of a particular PowerPoint. What I found will apparently print off the entire thing if it's able to before PowerPoint closes again, but I'm trying to get it to print specific pages. How would I alter the code below to do that so I can attempt to test this without printing off a ton of pages? Appreciate the help!

Try this modification.[vba]Sub test()
Dim PPT As Object



Set PPT = CreateObject("powerpoint.Application")
PPT.Visible = True



PPT.Presentations.Open ("C:\Documents and Settings\Pete Bryant\Desktop\test\a.ppt")
PPT.ActivePresentation.PrintOut
PPT.ActivePresentation.Close



PPT.Presentations.Open ("C:\Documents and Settings\Pete Bryant\Desktop\test\b.ppt")
PPT.ActivePresentation.PrintOut
PPT.ActivePresentation.Close



PPT.Quit
Set PPT = Nothing
End Sub[/vba]
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
The PrintOut method contains parameters that allow you to choose which slides to print. Have a look at the following link...


So, for example, to print slides 2 to 5...

VBA Code:
ActivePresentation.PrintOut From:=2, To:=5

Hope this helps!
 
Upvote 0
The PrintOut method contains parameters that allow you to choose which slides to print. Have a look at the following link... So, for example, to print slides 2 to 5...
VBA Code:
ActivePresentation.PrintOut From:=2, To:=5
Hope this helps!

I appreciate the help! So it doesn't quite work still, but we're getting closer. When I run either of them it appears to open Powerpoint and attempt to print and at some point it crashes and locks up the computer. I thought that maybe it was closing too early so I tried to add a wait in there to see if it would help, but it also did the same thing. Any ideas why it would compile fine and appear to somewhat work but end up crashing things in the end? (Code below is with the "Wait" line added, but if you take that out that's the same code I used that crashed it the first time).

Sub PrintPowerPoint()

Dim PPT As Object



Set PPT = CreateObject("powerpoint.Application")

PPT.Visible = True


PPT.Presentations.Open ("D:\FileLocation.pptx")

PPT.ActivePresentation.PrintOut From:=1, To:=2

Application.Wait (Now + TimeValue("0:00:10"))

PPT.ActivePresentation.Close


PPT.Quit

Set PPT = Nothing

End Sub
 
Upvote 0
Does this help?

VBA Code:
Option Explicit

Sub PrintPowerPoint()

    Dim pptApp As Object
    Set pptApp = CreateObject("Powerpoint.Application")
  
    pptApp.Visible = True
  
    Dim pptPres As Object
    Set pptPres = pptApp.Presentations.Open("c:\users\domenic\desktop\presentation1.pptx") 'change the path and filename accordingly
  
    PauseMacro 10 'seconds
  
    pptPres.PrintOut From:=1, To:=2
  
    PauseMacro 10
  
    pptPres.Close
  
    pptApp.Quit
  
    Set pptApp = Nothing
    Set pptPres = Nothing

End Sub

Sub PauseMacro(ByVal secs As Long)

    Dim endTime As Single
    endTime = Timer + secs
  
    Do
        DoEvents
    Loop Until Timer > endTime
  
End Sub
 
Upvote 0
Solution
Does this help?

VBA Code:
Option Explicit

Sub PrintPowerPoint()

    Dim pptApp As Object
    Set pptApp = CreateObject("Powerpoint.Application")
 
    pptApp.Visible = True
 
    Dim pptPres As Object
    Set pptPres = pptApp.Presentations.Open("c:\users\domenic\desktop\presentation1.pptx") 'change the path and filename accordingly
 
    PauseMacro 10 'seconds
 
    pptPres.PrintOut From:=1, To:=2
 
    PauseMacro 10
 
    pptPres.Close
 
    pptApp.Quit
 
    Set pptApp = Nothing
    Set pptPres = Nothing

End Sub

Sub PauseMacro(ByVal secs As Long)

    Dim endTime As Single
    endTime = Timer + secs
 
    Do
        DoEvents
    Loop Until Timer > endTime
 
End Sub
Domenic,

I ended up going with the code below, but yours might also work so I will mark it as an answer as well. Through lots of trial and error I was able to get it to work, so thank you very much for getting me close enough to get it to work!

Sub PrintPowerPoint()
Dim PPT As Object


Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True


PPT.Presentations.Open ("D:\FEENIX\FEENIX Planning\2) PowerPoint Mission Planning.pptx")
PPT.ActivePresentation.UpdateLinks
PPT.ActivePresentation.PrintOut From:=5, To:=6
PPT.ActivePresentation.Close

Application.Wait (Now + TimeValue("0:00:07"))

PPT.Quit
Set PPT = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top