Consulting

Results 1 to 8 of 8

Thread: VBA Code to change Powerpoint view from "Normal" to Slideshow"

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    12
    Location

    Question VBA Code to change Powerpoint view from "Normal" to Slideshow"

    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

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,882
    Location
    If you have a reference to the presentation then:

    [VBA]objPptPres.SlideShowSettings.Run[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Aug 2009
    Posts
    12
    Location

    Question

    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...


    [VBA]Sub SlideShowMode()

    objPptPres.SlideShowSettings.Run

    End Sub[/VBA]


    and came up with this error here...

    Run-Time Error 424
    Object Required
    Any thoughts?

    Thanks

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,882
    Location
    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!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    Aug 2009
    Posts
    12
    Location
    Here you go...

    [VBA]'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)[/VBA]

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,882
    Location
    and

    [vba]ppPres.SlideShowSettings.Run [/vba]

    doesn't work?

    If you have a presentation open you should really use GetObject instead of CreateObject BTW
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    VBAX Regular
    Joined
    Aug 2009
    Posts
    12
    Location

    Thumbs up

    Okay, my bad here.

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



    [VBA] ' Clean up
    ' Set PPSlide = Nothing
    ' Set PPPres = Nothing
    ' Set PPApp = Nothing
    End If
    [/VBA]

    Once I took that out, it was ALL GOOD.

    Thanks very much for your help!

  8. #8
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,882
    Location
    Yep, what is probably happenning is the code got to the cleanup before the PowerPoint stuff had time to work.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •