turn static macro into dynamic

A

andy

I would like a macro to insert a blank slide, insert and
position a text box, change font size, change to bold, and
center the text, leaving the text box in place (even if it
says "Type Here!"). I recorded the following macro,
however it produces the folowing error: Runtime error '-
2147188160 (80048240'): Shape (unknown member): Invalid
Request. To select a shape, its view must be active.
However if you are on slide #11 (Index:=11), as I was when
I recorded the macro (see the 2nd line of code below, the
1st line of code to begin with ActiveWindow...), the macro
will do exactly what I had intended it to do.

Instead of hard-coding the Index:=11, can powerpoint code
find the location of the slide which is currently active,
and execute the macro based on that location (insert after
the current slide). Perhaps if the current slide Index can
be determined, then that parameter can be substituted (in
the line below in the Index:= 11) and in that way the
macro would insert, etc. after the current position just
as I would like dynamically.

Thank you in advance
God bless you

Here is the code:
Sub NewSlideInsertTextBoxAndFormat()
ActiveWindow.View.GotoSlide
Index:=ActivePresentation.Slides.Add(Index:=11,
Layout:=ppLayoutBlank).SlideIndex
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox
(msoTextOrientationHorizontal, 0#, 0#, 720#, 36#).Select
ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap =
msoTrue
ActiveWindow.Selection.TextRange.Font.Size = 54
ActiveWindow.Selection.TextRange.Font.Bold = msoTrue

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Parag
raphs(Start:=1, Length:=1).ParagraphFormat.Alignment =
ppAlignCenter

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Chara
cters(Start:=1, Length:=0).Select
With ActiveWindow.Selection.TextRange
.Text = "Type Here!"
With .Font
.Name = "Times New Roman"
.Size = 54
.Bold = msoTrue
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
ActiveWindow.Selection.Unselect
End Sub
 
D

David M. Marcovitz

Are you trying to do this while running a slide show (in Slide Show View)
or while editing a slide show (in Edit or Normal View). The macro you
have is set up for Edit or Normal View. If what you mean by dynamically
is that you want to do it while in Slide Show View, I can get you a good
example or two (hopefully, I'll have some on my Web site soon, but the
site is not complete yet--
http://www.loyola.edu/education/PowerfulPowerPoint/).
--David

--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
A

andy

David,
Thank you for your reply. I'm sorry I was not more
clear. What I ment by dynamic was that instead of the
static Index:=11, that the Index would be dynamically
updated with the Index of the currently active slide. I am
using PP2K, and I am speaking of in Edit mode, not
presentation.

Again, thank you
God bless you
 
S

Shyam Pillai

Andy,
I think what you are looking for is this line of code :

ActiveWindow.View.GotoSlide _
Index:=ActivePresentation.Slides.Add( _
Index:=ActivePresentation.Slides.Count + 1, _
Layout:=ppLayoutBlank).SlideIndex
 
A

andy

Shyam,

Praise God! This is exactly what I was looking for.
Thank you so very much for helping me.

God bless you
Andy
 
A

andy

Shyam,

I think I spoke to soon before testing completely. Yes,
the code line works however it puts the new slide at the
end of the entire presentation. I would like the new slide
to be inserted where ever I am. For example if I am on
slide 20, I want the new slide to inserted as slide 21.
Right now if I am on slide 20 and run the macro it inserts
at the end, and if there are many slides, the new one will
go at the end, potentially slide numbers are in the
hundreds!!!

Is there code which code detect what the current slide
number is, and then add one?

Thank you in advance,
God bless you
 
D

David M. Marcovitz

Try this one (just a variation on Shyam's code):

ActiveWindow.View.GotoSlide _
Index:=ActivePresentation.Slides.Add( _
Index:=ActiveWindow.View.Slide.SlideIndex + 1, _
Layout:=ppLayoutBlank).SlideIndex

I work more on things in Slide Show View than Edit View, but this seems
to work even though the VBA editor doesn't seem happy when I type it.
Anyone know why the editor beeps at me after I type
ActiveWindow.View.Slide. rather than offering me choices (like
SlideIndex)?

--David

--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
A

andy

Shyam,
Thank you again. I thank God I believe that I have what
I need. I did the following:

dim SlidePosition as Integer
SlidePosition = ActiveWindow.View.Slide.SlideIndex

ActiveWindow.View.GotoSlide _
Index:=ActivePresentation.Slides.Add( _
Index:=SlidePosition + 1, _
Layout:=ppLayoutBlank).SlideIndex

If you see a flaw with this, or if there is a builtin for
current, or active slide index position, please let me know
Thank you again for your help
God bless you
 
A

andy

David,
Thanks. I was going about it in a round about way (see
my 3rd post to Shyam's reply) by declaring a variable,
filling it with the SlideIndex, then using the variable
and incrementing by 1. Thank God, they both work but I
like your, more direct approach better.

Thank you
God bless you
 

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