My shapes remain invisible although the macro appears to work?

P

Preschool Mike

Hi, I'm attempting to create a presentation for my preschool class where when
a letter (shape) is clicked another shape (same letter) appears in the
presentation. My problem is the code works on slide 2 but not on other
slides (e.g., the shapes won't appear). I have a button (test for "right
answer") on each slide that allows them to go onto the next slide pending all
the shapes are visible, if they are not they can't advance. When I run the
presentation slide 2 works perfectly. I click on all the correct letters to
spell the word and all the shapes appear. I check my work and can advance to
the next slide. When I get to the next slide I click on all the correct
letters and the shapes don't appear but when I check my work I can advance to
the next slide. I have a feedback button at the end of the presentation that
tells how "I did". When I click on it I get that I answered everything
correctly. If I run the macros in design view they work perfectly (my shapes
appear). Need some help. Hope I explained this well. I'm pretty sure my
codes are good.
 
P

Preschool Mike

Here's the code for my project. I'm just learning all of this so some of it
may not make any sense. Thanks for your help

Dim numCorrect As Integer
Dim numIncorrect As Integer
Dim userName As String
Dim qAnswered As Boolean
Dim numSlides As Long
Dim numRead As Integer
Dim numWanted As Integer
Dim visited() As Boolean
Dim rightUser As String

Sub GetStarted()
Initialize
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub selectUser(nameButton As Shape)
userName = nameButton.TextFrame.TextRange.Text
rightUser = MsgBox("Are you " & userName & "? ", vbYesNo)
If rightUser = vbYes Then
GetStarted
Else
MsgBox ("Sign in again")
End If
End Sub
Sub CheckAnswer1()
If ActivePresentation.Slides(2).Shapes("cbox").Visible = True And _
ActivePresentation.Slides(2).Shapes("abox").Visible = True And _
ActivePresentation.Slides(2).Shapes("tbox").Visible = True Then
RightAnswer
Else
MsgBox ("Keep Trying")
End If
End Sub
Sub CheckAnswer2()
If ActivePresentation.Slides(3).Shapes("bbox").Visible = True And _
ActivePresentation.Slides(3).Shapes("abox2").Visible = True And _
ActivePresentation.Slides(3).Shapes("tbox2").Visible = True Then
RightAnswer
Else
MsgBox ("Keep Trying")
End If
End Sub
Sub CheckAnswer3()
If ActivePresentation.Slides(4).Shapes("ccow").Visible = True And _
ActivePresentation.Slides(4).Shapes("ocow").Visible = True And _
ActivePresentation.Slides(4).Shapes("wcow").Visible = True Then
RightAnswer
Else
MsgBox ("Keep Trying")
End If
End Sub

Sub HideShapes()
ActivePresentation.Slides(2).Shapes("cbox").Visible = False
ActivePresentation.Slides(2).Shapes("abox").Visible = False
ActivePresentation.Slides(2).Shapes("tbox").Visible = False
ActivePresentation.Slides(3).Shapes("bbox").Visible = False
ActivePresentation.Slides(3).Shapes("abox2").Visible = False
ActivePresentation.Slides(3).Shapes("tbox2").Visible = False
ActivePresentation.Slides(4).Shapes("ccow").Visible = False
ActivePresentation.Slides(4).Shapes("ocow").Visible = False
ActivePresentation.Slides(4).Shapes("wcow").Visible = False
End Sub
Sub Showcbox()
ActivePresentation.Slides(2).Shapes("cbox").Visible = True
End Sub
Sub showabox()
ActivePresentation.Slides(2).Shapes("abox").Visible = True
End Sub
Sub Showtbox()
ActivePresentation.Slides(2).Shapes("tbox").Visible = True
End Sub
Sub Showbbox()
ActivePresentation.Slides(3).Shapes("bbox").Visible = True
End Sub
Sub Showabox2()
ActivePresentation.Slides(3).Shapes("abox2").Visible = True
End Sub
Sub Showtbox2()
ActivePresentation.Slides(3).Shapes("tbox2").Visible = True
End Sub
Sub Showccow()
ActivePresentation.Slides(4).Shapes("ccow").Visible = True
End Sub
Sub Showocow()
ActivePresentation.Slides(4).Shapes("ocow").Visible = True
End Sub
Sub Showwcow()
ActivePresentation.Slides(4).Shapes("wcow").Visible = True
End Sub
Sub YourName()
userName = InputBox(prompt:="Type your name") 'Optional sign in by
typing in student name
GetStarted
RandomNext
End Sub

Sub Initialize()

HideShapes
numWanted = ActivePresentation.Slides.Count
numRead = 0
numSlides = ActivePresentation.Slides.Count
ReDim visited(numSlides)
For i = 2 To numSlides - 1
visited(i) = False
Next i
numCorrect = 0
numIncorrect = 0
qAnswered = False

End Sub

Sub RightAnswer()
If qAnswered = False Then
numCorrect = numCorrect + 1
End If
qAnswered = False
visited(ActivePresentation.SlideShowWindow.View.Slide.SlideIndex) = True
numRead = numRead + 1
ActivePresentation.SlideShowWindow.View.Next
End Sub
Sub WrongAnswer()
If qAnswered = False Then
numIncorrect = numIncorrect + 1
End If
qAnswered = True
End Sub
Sub Feedback()
MsgBox ("You got " & numCorrect & " out of " & numCorrect + numIncorrect
& ", " & userName)
End Sub
Sub Quit()
ActivePresentation.Close
End Sub
Sub StartAgain()
ActivePresentation.SlideShowWindow.View.GotoSlide (1)
End Sub
Sub RandomNext()
Dim nextSlide As Long

If numRead >= numWanted Or numRead >= numSlides - 2 Then
ActivePresentation.SlideShowWindow.View.Last
Else
nextSlide = Int((numSlides - 2) * Rnd + 2)
While visited(nextSlide) = True
nextSlide = Int((numSlides - 2) * Rnd + 2)
Wend
ActivePresentation.SlideShowWindow.View.GotoSlide (nextSlide)
End If
End Sub
Sub SetObjectName()
Dim objectName As String

If ActiveWindow.Selection.Type = ppSelectionShapes _
Or ActiveWindow.Selection.Type = ppSelectionText Then
If ActiveWindow.Selection.ShapeRange.Count = 1 Then
objectName = InputBox(prompt:="Type a name for the object")
objectName = Trim(objectName)
If objectName = "" Then
MsgBox ("You did not type anything. " & _
"the name will remain " & _
ActiveWindow.Selection.ShapeRange.Name)
Else
ActiveWindow.Selection.ShapeRange.Name = objectName
End If
Else
MsgBox _
("You can not name more than one shape at a time. " _
& "Select only one shape and try again.")
End If
Else
MsgBox ("No shapes are selected.")
End If
End Sub

Sub SetSlideName()
Dim slideName As String

slideName = InputBox(prompt:="Type a name for the slide")
slideName = Trim(slideName)
If slideName = "" Then
MsgBox ("you did not type anything. " & _
"The name will remain " & _
ActiveWindow.View.Slide.Name)
Else
ActiveWindow.View.Slide.Name = slideName
End If
End Sub

Sub GetSlideName()
MsgBox ActiveWindow.View.Slide.Name
End Sub
Sub GetObjectName()
If ActiveWindow.Selection.Type = ppSelectionShapes _
Or ActiveWindow.Selection.Type = ppSelectionText Then
If ActiveWindow.Selection.ShapeRange.Count = 1 Then
MsgBox (ActiveWindow.Selection.ShapeRange.Name)
Else
MsgBox ("You have selected more than one shape.")
End If
Else
MsgBox ("No shapes are selected.")
End If
End Sub
 
D

David Marcovitz

Actually, the code makes perfect sense. Most of it looks very familiar.
I like what you've done to it. My guess is that you have animations (or
animated GIFs) on the slides that don't work. The Visible property
sometimes doesn't work well on slides with animations (or animated
GIFs). Unfortunately, I have seen this problem intermittently so it will
work with some slides and not others. For example, slide 2 (the one that
works) might have animated GIFs on it just like the other slides, but it
might work anyway even though the animated GIFs are interfering with the
other slides.
--David
 
P

Preschool Mike

Thanks for your help. The code should look familiar - I read your book and
have become a fan of it and your web site. I do have animation on the slides
but no animated gifs. I'll try it again without the animation.
 

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