Activate a slide

B

Bob

I'm trying to write a macro that creates a new slide at the end of a
presentation, creates a text box on it, and pastes text into the text box.
Here's the pertinent code:

ActivePresentation.Slides.Add(Index:=NumSlides + 1,
Layout:=ppLayoutText).Select
ActiveWindow.Selection.SlideRange.Layout = ppLayoutBlank
ActivePresentation.Slides(NumSlides + 1).FollowMasterBackground = msoFalse
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo
ntal, 0, 0, 720, 36).Select
With ActiveWindow.Selection.ShapeRange
.TextFrame.WordWrap = msoTrue
(other properties)
End With
ActiveWindow.Selection.TextRange.Font.Color.RGB = RGB(0, 0, 0)
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1,
Length:=0).Select
ActiveWindow.Selection.TextRange.Text = CommentList

NumSlides and CommentList are "Dim"ed as Integer and String, respectively.

When I run the macro, it breaks in line 4 (adding the text box), and gives
the following error message:

Run-time error '-2147188160 (80048240)':
Shape (unknown member): Invalid request. To select a shape, its view must
be active.

Going back to the presentation, the new slide is not, in fact, active, so
this seems to make sense. However, if I put a breakpoint in the macro
(before line 4) and step through (F8) the rest of it, the macro works fine.

How do I get the slide active? I've tried playing with panes, windows, and
views, with no success. I've also tried using "Refresh" in different ways;
no joy here, either. Is there a different way to do this? What am I
missing?

Thanks,
Bob
 
P

PoohsMate

Bob
There is an example of this in the book Powerful Powerpoint for educators -
try this as a search and you should find it. If not let me know and I will
post code (but it is quite long). HTH Bernard
 
D

David M. Marcovitz

As Bernard suggests, you might find examples of this in my book (see
http://www.PowerfulPowerPoint.com/). However, you are trying to do this
in Normal View, and my book shows ways to do this in Slide Show View.

Why don't you try:

Dim oSld as Slide

oSld = ActivePresentation.Slides.Add(Index:=NumSlides + 1, ...

Then, instead of using ActiveWindow.Selection.SlideRange, you can use
oSld.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
B

Bob

Thanks, PM,

I will try to buy a copy of the book - looks helpful! There are quite a few
online examples and I haven't had time to look through all of them yet, but
the ones I saw look like they're activating a slide in a slideshow. I'm
tring to activate (or display) a slide in edit mode. Is there a difference?
If it's not too much trouble, could you post the example code so I can take
a look at it before getting the book?

Thanks, again!
Bob
 
D

David M. Marcovitz

Bob,

You are right about the Edit mode vs. slide mode thing. Note that all
examples from the book are already online at
http://www.PowerfulPowerPoint.com/ and the code is even in text form. You
might want to start with Example 7.9 (click "Examples by Chapter" and
"Chapter 7").

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
B

Bob

Thanks for all of the suggestions - they worked! I used objects and was
able to get the macro working. Well, until I ran into one odd problem.
When I run the macro in a short presentation (less than 10 or 11 slides), it
does exactly what I want it to:

1) Gather all comments.
2) Insert new slide at end.
3) Insert text box on new slide.
4) Insert list of comments.

If I run the macro in a longer presentation, it gathers the comments and
inserts a new slide at the end, but it then puts the text box on the *first*
slide! It does put the comments in the new text box, but why is the text
box added to the first slide, not to the last? Why does the length of the
presentation matter?

For reference, and for your use (if anyone wants it!), here's the "working"
code:

Sub Comments2Slide()
Dim SlideThis As Slide
Dim CommentThis As Comment
Dim CommentList As String
Dim NumSlides As Long
Dim SlideWidth As Long
Dim SlideHeight As Long
Dim CommentSlide As Slide
Dim CommentTextBox As Shape
NumSlides = ActivePresentation.Slides.Count
SlideWidth = ActivePresentation.Slides(1).Master.Width
SlideHeight = ActivePresentation.Slides(1).Master.Height
' Gather comments....................
For Each SlideThis In ActivePresentation.Slides
For Each CommentThis In SlideThis.Comments
CommentList = CommentList & "Slide #" & SlideThis.SlideNumber & " -
" & CommentThis.Text & vbCrLf
Next CommentThis
Next SlideThis
' Create new slide....................
Set CommentSlide = ActivePresentation.Slides.Add(Index:=NumSlides + 1,
Layout:=ppLayoutText)
With CommentSlide
.Layout = ppLayoutBlank
.FollowMasterBackground = msoFalse
'Create text box....................
Set CommentTextBox =
ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizo
ntal, 0, 0, SlideWidth, SlideHeight)
With CommentTextBox
.TextFrame.WordWrap = msoTrue
.TextFrame.AutoSize = ppAutoSizeShapeToFitText
.Fill.Transparency = 0#
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
' Put comments in text box....................
.TextFrame.TextRange.Text = CommentList
.TextFrame.TextRange.Font.Name = "Arial Narrow"
.TextFrame.TextRange.Font.Size = 10
End With
End With
End Sub
 
B

Bob

Arrggghhh.... I removed the ".Select" from the end of the line, but didn't
rewrite the whole line. Bad editor. BAD! (woof, woof).

Rewriting the line causes the macro now to place the text box on the last
slide. More importantly, I understand why! What I don't understand is why
the old code put the text box on the last slide in short presentations and
on the first slide in longer presentations. Any ideas?

BTW, thanks to your advice, I wrote a Word macro last night using discrete
Dims and objects. It worked the first time! I will try to use objects,
rather than selections, where possible in the future.

Thanks!

Bob
 
B

Bob

Hot dog - a food thread! Let me ketchup on the notes, 'cause I relish
talking with folks who can really cut the mustard. Hang onion - t'll only
take a mint.

OK, back to the tapioca - er... topic. For consistency, I always went to
slide 1 before running the macro. In all cases, the new slide was added at
the end. In short presentations, the text box was added on the last, new
slide. In longer presentations, while the slide was added at the end, the
text box was added to slide 1 (which *was* the slide I was on). My guess is
that for longer presentations, when I was working with the Selection method,
the program could not "get to" the last slide quickly enough and, so, worked
on slide 1.

Just to confuse things, I went back to my long test presentation and tried
running the old macro from page 1 as well as from other pages. Running the
macro from page 1 put the text box on page 1. Running it from other pages
put the macro on the last slide! Re-running the macro from page 1 still put
the text box on the last page!!

Of course, the macro is working and I learned a lot, for which I am
grateful, so this thread is now about how VBA works, but it's interesting,
nonetheless.

Thanks for the kelp - er... help,
Bob
 
E

Echo S

Bob said:
Hot dog - a food thread! Let me ketchup on the notes, 'cause I relish
talking with folks who can really cut the mustard. Hang onion - t'll only
take a mint.

OK, back to the tapioca - er... topic.
Thanks for the kelp - er... help,

ROFL!

I dunno much about code, Bob, but it sounds to me as if something's
definitely burgered somewhere. Totally fried, if you ask me.

Kinda leaves you in a pickle, doesn't it?

;-)
 
K

Kathy Jacobs

Echo S said:
Kinda leaves you in a pickle, doesn't it?

Sweet or dill?

--
Kathryn Jacobs, Microsoft MVP PowerPoint and OneNote
Author of Kathy Jacobs on PowerPoint - Available now from Holy Macro! Books
Get PowerPoint answers at http://www.powerpointanswers.com

I believe life is meant to be lived. But:
if we live without making a difference, it makes no difference that we lived
 

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