How to Insert a slide after the selected slide.

C

Coogrr

I want a macro that always inserts a new slide after the selected
slide. I don't think I need the Index:= command unless I can figure out

how to make it reflect the selected side each time.


Here is what I have and it inserts a new slide after the #2 slide each
time.


'Insert new slide'
'
ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).Select
ActiveWindow.Selection.SlideRange.Layout = ppLayoutBlank


Any ideas on how to change this to make it do what I need it to do?

Thanks,


Dennis
 
S

Steve Rindsberg

Coogrr said:
I want a macro that always inserts a new slide after the selected
slide. I don't think I need the Index:= command unless I can figure out

how to make it reflect the selected side each time.

Here is what I have and it inserts a new slide after the #2 slide each
time.

'Insert new slide'
'
ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).Select
ActiveWindow.Selection.SlideRange.Layout = ppLayoutBlank

Call ActivePresentation.Slides.Add( _
ActiveWindow.Selection.SlideRange(1).SlideIndex, _
ppLayoutBlank)

Test ActiveWindow.Selection.Type to make sure it's what you expect (ie, slides
and not shapes or nothing)
 
C

Coogrr

Thanks but this does the same as before. It inserts a new slide above
the selected slide. Maybe it is impossible to have code to insert a
slide below the active slide. I guess I will just abandon the idea and
just have the user insert the slide using the insert menu. I was just
trying to eliminate a few mouse clicks. I should have expected the
worse from MS code, lol.

Dennis
 
S

Steve Rindsberg

Coogrr said:
Thanks but this does the same as before.

No, before it was inserting a slide at 2 each time, if you'll recall.
It inserts a new slide above
the selected slide. Maybe it is impossible to have code to insert a
slide below the active slide.

You didn't say that's what you wanted. If you want to change the position
where the slide's inserted, simply change "SlideIndex" below to "SlideIndex -
1" or whatever you want.

ActiveWindow.Selection.SlideRange(1).SlideIndex gives you the number of the
current slide (or actually the first slide in the current range but if you're
in Normal view, it amounts to the same thing)

Call ActivePresentation.Slides.Add( _
ActiveWindow.Selection.SlideRange(1).SlideIndex, _
ppLayoutBlank)

I guess I will just abandon the idea and
just have the user insert the slide using the insert menu. I was just
trying to eliminate a few mouse clicks. I should have expected the
worse from MS code, lol.

Maybe I just haven't had enough coffee and am in a bad mood, but that strikes
me as pretty ratty attitude. It's perfectly possible to do what you (seem to)
want. You just have to explain what it is.
 
C

Coogrr

I don't want to start an argument. In my very first post I said "I want
a macro that always inserts a new slide after the selected slide." I
thought that made it clear that I wanted to insert a slide after the
slide that was selected just like what happens when you go to Insert
--> New Slide.

And apparently that is not possible via a macro. As far as attitude, I
will waste more time attempting to get a macro to do what Insert -->
New Slide will do then the time it will take 1000 users to do the extra
clicks.

Dennis
 
C

Coogrr

Not elegant but I did get this code to do what I wanted.

Sub Macro2()
'
' Macro recorded 10/25/2005 by Dennis Crowley
'
Dim S As Integer
S = ActiveWindow.Selection.SlideRange.SlideIndex 'record index
number of current slide'

ActivePresentation.Slides.Add(Index:=S + 1,
Layout:=ppLayoutBlank).Select 'insert new slide below current slide'

End Sub

Dennis
 
S

Steve Rindsberg

Coogrr said:
I don't want to start an argument. In my very first post I said "I want
a macro that always inserts a new slide after the selected slide."

This is where quoting comes in handy. Later you switched to "above/below"
which is less obvious; my suggested change to the code would give you a slide
one PRIOR to the selected slide but as I pointed out, you can change the
arithmetic to make it one after, three after or whatever you like.

It's more or less the same as what you came up with, but one suggestion: use
Longs rather than Integers. It's not a big thing, but in general it's a good
habit to get into, using the correct data type (and PPT's SlideID and
SlideIndex both use Longs)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top