PDA

View Full Version : Solved: Macro not running in slide show mode



Paul Benson
09-29-2009, 08:55 AM
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

Cosmo
09-29-2009, 09:02 AM
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:
Public Sub moveSlideToEnd()
ActivePresentation.Slides(1).MoveTo (ActivePresentation.Slides.Count)
End Sub


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.

Paul Benson
09-29-2009, 09:31 AM
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.


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


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

Paul Benson
09-29-2009, 10:05 AM
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

Cosmo
09-29-2009, 11:34 AM
Try this:
ActivePresentation.Slides(x).Cut
ActivePresentation.Slides.Paste(y)

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

Paul Benson
09-29-2009, 12:42 PM
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.

John Wilson
10-05-2009, 08:08 AM
This will shuffle a range in both edit or show mode

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