Consulting

Results 1 to 7 of 7

Thread: Solved: Macro not running in slide show mode

  1. #1

    Solved: Macro not running in slide show mode

    Hi, first time in this forum.
    I have done quite a bit of VBA in Excel and am trying to expand into powerpoint. I created a macro which successfully shuffles the slides, but it only works in Normal and 'Slide Sorter' views. I haven't tried Notes view, but it definitely does not work in slide show mode.

    I have the macro assigned to a button on the first slide to shuffle the other slides. The button 'depresses' on the screen but nothing happens. I created a test macro which causes the button press to go to a certain slide and that does work. (It also appears that breakpoints are ignored in slide show mode, but that is a different matter).

    Is it illegal to move pages around once in slide show mode? Kind of a bummer if I can't because then for the user to shuffle they will need to run it from the 'Run Macro' command. BTW, this is powerpoint 2000 I'm working on, but I also have access to 2007.

    Thank you in advance,
    Pauley

  2. #2
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    Quote Originally Posted by Paul Benson
    Hi, first time in this forum.
    I have done quite a bit of VBA in Excel and am trying to expand into powerpoint. I created a macro which successfully shuffles the slides, but it only works in Normal and 'Slide Sorter' views. I haven't tried Notes view, but it definitely does not work in slide show mode.

    I have the macro assigned to a button on the first slide to shuffle the other slides. The button 'depresses' on the screen but nothing happens. I created a test macro which causes the button press to go to a certain slide and that does work. (It also appears that breakpoints are ignored in slide show mode, but that is a different matter).

    Is it illegal to move pages around once in slide show mode? Kind of a bummer if I can't because then for the user to shuffle they will need to run it from the 'Run Macro' command. BTW, this is powerpoint 2000 I'm working on, but I also have access to 2007.

    Thank you in advance,
    Pauley
    In 2007, I am able to move slides while in slide show mode. I will check in 2000 in a little bit.

    What code are you using, perhaps the error is there.

    e.g., this code will move the first slide to the end of the presentation:
    [vba]Public Sub moveSlideToEnd()
    ActivePresentation.Slides(1).MoveTo (ActivePresentation.Slides.Count)
    End Sub
    [/vba]

    Edit: the MoveTo method is not available in 2000; I tried recording a macro moving a slide, and nothing was recorded, and I didn't see any editable properties/methods to allow me to do so, so it's probably not possible to move the slide in 2000.

  3. #3
    Here is my routine. I don't like using select, but I'm just learning. I see that MoveTo is what I would prefer, but, as you said, that appears to not be available in 2000.

    [VBA]
    Sub shuffle()

    Dim lcv As Integer
    Dim shuf As Integer
    Dim first As Integer
    Dim last As Integer

    first = 2
    Randomize
    last = ActivePresentation.Slides.Count
    For lcv = last To (first + 1) Step -1
    shuf = Int(((lcv - first + 1) * Rnd) + first) 'random # between first and i, inclusive
    ActivePresentation.Slides(shuf).Select
    ActiveWindow.Selection.Cut
    ActivePresentation.Slides(lcv - 1).Select
    ActiveWindow.View.Paste
    Next

    End Sub
    [/VBA]

    The code is a little convoluted since I want it to just shuffle between my first and last slide (inclusive). In other words in a 20 slide presentation, if first=5 and last =12 then only slides 5-12 are shuffled.

    Thanks,
    Pauley

  4. #4
    I think it may have something to do with my use of ActiveWindow. I had to use that since, oddly, ActivePresentation.Slides(x).Cut exists, but ActivePresentation.Slides(x).Paste does not.

    Pauley

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    Try this:
    [VBA]ActivePresentation.Slides(x).Cut
    ActivePresentation.Slides.Paste(y)[/VBA]

    where x is the slide you want to move, and y is the new position.

  6. #6
    Yes, that did work.
    My son has 2007 on his computer, so I actually switched to your MoveTo solution. Much cleaner solution.

    Thank you,
    Pauley

    I saw some posts marked as solved. I'll mark this thread that way when I figure out how to do it.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    This will shuffle a range in both edit or show mode

    [VBA]Sub shufflerange()
    Dim Iupper As Integer
    Dim Ilower As Integer
    Dim Ifrom As Integer
    Dim Ito As Integer
    Dim i As Integer
    Iupper = 12
    Ilower = 5

    For i = 1 To 2 * Iupper
    Randomize
    Ifrom = Int((Iupper - Ilower + 1) * Rnd + Ilower)
    Ito = Int((Iupper - Ilower + 1) * Rnd + Ilower)
    ActivePresentation.Slides(Ifrom).MoveTo (Ito)
    Next i

    End Sub[/VBA]
    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
  •