vba code troubles

C

Candace

Does anyone see anything wrong with the following code? I have the
"PrepareSlide22" procedure tied to a picture using "Action Settings", but
nothing happens when I click the picture that this macro is tied to. The
picture that I am clicking is on slide 21. It does not cause the slideshow to
advance to the next slide (slide 22), which is what I want the
macro/procedure to accomplish. Am I doing something wrong here?

Dim correctCube As Integer

Sub PrepareSlide22()
Initialize
ActivePresentation.SlideShowWindow.View.Next
End Sub

Sub Initialize()
correctCube = 0
ActivePresentation.Slides(22).Shapes(16).Visible = msoFalse
End Sub
 
D

David M. Marcovitz

The code looks correct. However, this assumes that you hve a shape 16 on
slide 22. If not, then it would behave as you describe. Here are some
debugging thoughts (it looks like you might be getting some code from my
book, so you might want to look at the debugging tips in Chapter 9 if
you are):

(1) Try commenting out the Initialize line in PrepareSlide22. If it
still doesn't advance, the problem is not with the Initialize procedure.

(2) Check for animations on Slide 21.
ActivePresentation.SlideShowWindow.View.Next doesn't really go to the
next slide; it really runs the next animation. If there are none left,
it then goes to the next slide.

(3) Try compiling your code. Often there are hidden errors in other
parts of your code (I find that I often see two End Sub statements in a
row, but there are many other kinds of errors that will cause the whole
thing to stop working, and compiling often points you to these errorss,
which are usually not anywhere near the code you are trying to run).

--David
 
J

John Wilson

Assuming shape 16 exists I don't see anything wrong. I guess there's a reason
for the correctCube line but it seems to do nothing?

I would suggest using a shapename instead of shapes(16) though

--
-------------------------------------------
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk
 
D

David M. Marcovitz

Note that shapes are added in order to a slide, but if a shape is
deleted, all the later shapes are renumbered. So, if you draw a shape on
a blank slide, it will be Shapes(1). If you draw two more, they will be
Shapes(2) and Shapes(3). But if you now delete the second shape, then
the third shape will be renumbered to be Shapes(2). I believe that there
are other actions that can cause shape numbers to get changed, which is
why it is best to take John's suggestion and use shape names.

(Since I think you might be using my book, you should note that if I
were to rewrite the book, I would talk about naming shapes much earlier
in the book and avoid using numbers, especially with version 2007, where
naming shapes is so much easier).

--David
 
J

John Wilson

Just to add to David's explaination the Shape number is the zorder position.
Shapes(1) is the back shape and the highest number the front shape. As you
can easily see this can change with deletions, moving backward or forwards or
eben changing the slide layout. In 2003 or earlier the "name" in the
animation pane will tell you the current shape number. This is not true in
2007.
--
-------------------------------------------
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk
 
V

vindys

Hi,

I too feel it should be shape 16 itself. Better you give a error handling
statement for that statement

Sub PrepareSlide22()
Initialize
ActivePresentation.SlideShowWindow.View.Next
End Sub

Sub Initialize()
correctCube = 0
On Error GoTo AppErr
ActivePresentation.Slides(22).Shapes(16).Visible = msoFalse
Exit Sub
AppErr:
MsgBox "Couldn't find Shape 16"
End Sub
 

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