OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

Useful PowerPoint VBA code snippets

  • Determine the current slide in the Slide View mode:

    Sub SlideIDX()
    MsgBox "The slide index of the current slide is:" & _
            ActiveWindow.View.Slide.SlideIndex
    End Sub

  • Determine the current slide in Slide Show mode:

    Sub SlideIDX()
    MsgBox "The slide index of the current slide is:" & _
            ActivePresentation.SlideShowWindow.View.Slide.SlideIndex 
    End Sub

  • Difference between SlideIndex property and SlideNumber property:

    The SlideIndex property returns the actual position of the slide within the presentation. The SlideNumber property returns the PageNumber which will appear on that slide. This property value is dependent on "Number Slide from" option in the Page Setup.

    Go to Page Setup and Change the value of "Number Slide from" to 2 and then while on the 1st slide in Slide View run the following Macro


    Sub Difference()
    MsgBox "The Slide Number of the current slide is:" & _
            ActiveWindow.View.Slide.SlideNumber & _
            " while the Slide Index is :" & _
            ActiveWindow.View.Slide.SlideIndex
    End Sub

  • Macro to exit all running slide shows:

    Sub ExitAllShows()
    Do While SlideShowWindows.Count > 0
        SlideShowWindows(1).View.Exit
    Loop
    End Sub
  • Code to refresh current slide during the slide show:

    Sub RefreshSlide()
    Dim lSlideIndex As Long
    lSlideIndex = SlideShowWindows(1).View.CurrentShowPosition
    SlideShowWindows(1).View.GotoSlide lSlideIndex
    End Sub
  • Code to reset animation build for the current slide during the slide show:

    Sub ResetSlideBuilds()
    Dim lSlideIndex As Long
    lSlideIndex = SlideShowWindows(1).View.CurrentShowPosition
    SlideShowWindows(1).View.GotoSlide lSlideIndex, True

    End Sub

     
  • Insert a slide after current slide

    Sub InsertSlide()
    Dim oView As View
    With ActivePresentation.Slides
         Set oView = ActiveWindow.View
         oView.GotoSlide .Add(oView.Slide.SlideIndex + 1, _
                                           ppLayoutTitleOnly).SlideIndex
         Set oView = Nothing
    End With
    End Sub



 

Copyright 1999-2018 (c) Shyam Pillai. All rights reserved.