PDA

View Full Version : VBA Code to change Powerpoint view from "Normal" to Slideshow"



duugg
01-11-2012, 01:55 PM
Hello All,

I have an Excel workbook with VBA code to manipulate PowerPoint. I managed to do all kinds of things to PowerPoint from within Excel VBA.

However, my dilemma is that I want my Excel code to end by switching focus to the only PowerPoint presentation open at that time and then change it from "Normal" view to "Slide Show" view.

Does anyone know if this can be done?


Thanks

John Wilson
01-12-2012, 02:46 AM
If you have a reference to the presentation then:

objPptPres.SlideShowSettings.Run

duugg
01-12-2012, 06:47 AM
Thanks for the reply but I put that code in the last line of code in my Excel module and ran it. After running it, I when to PowerPoint, and it still showed up in "Normal" mode.

I even tried running that code directly from within PowerPoint VBA like this...


Sub SlideShowMode()

objPptPres.SlideShowSettings.Run

End Sub


and came up with this error here...


Run-Time Error 424
Object Required

Any thoughts?

Thanks

John Wilson
01-12-2012, 06:53 AM
It looks like objPptPres is NOT a reference to your PowerPoint Presentation. How do you reference the presentation in your Excel Code? Maybe post a snippet!

duugg
01-12-2012, 07:58 AM
Here you go...

'Sub AAAAChartToPresentation3()
' Set a VBE reference to Microsoft PowerPoint 10.0 Object Library for Office 2002,

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide


Dim oPPT As PowerPoint.Application
Set oPPT = CreateObject("PowerPoint.Application")

' Sub PasteChartintoPP2()
'
' PasteChartintoPP Macro
' Keyboard Shortcut: Ctrl+Shift+A

' Dim PPApp As PowerPoint.Application
' Dim PPPres As PowerPoint.Presentation
' Dim PPSlide As PowerPoint.Slide
Dim PresentationFileName As Variant

' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation

' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)

John Wilson
01-12-2012, 08:23 AM
and

ppPres.SlideShowSettings.Run

doesn't work?

If you have a presentation open you should really use GetObject instead of CreateObject BTW

duugg
01-12-2012, 10:09 AM
Okay, my bad here.

I only gave you a "snippet" of code as you said. Here's the crucial part I left out.



' Clean up
' Set PPSlide = Nothing
' Set PPPres = Nothing
' Set PPApp = Nothing
End If


Once I took that out, it was ALL GOOD.

Thanks very much for your help!

John Wilson
01-12-2012, 10:53 AM
Yep, what is probably happenning is the code got to the cleanup before the PowerPoint stuff had time to work.