Solved

Powerpoint Macro

Posted on 2011-02-21
6
813 Views
Last Modified: 2012-05-11
I am making a simple powerpoint training quiz to run in Powerpoint 2007 amd 2010 and I'm almost there -
I've just got a couple of issues with the final 'results' slide.

What I has hoping to do was:

When the slide appears - enter some text into a pre-existing text box along the lines of
TextBox1.TextFrame.TextRange.Text = "your score was " + QScore + "out of "+QMax + ". Thank you"

But I can't seem to be able to do this, or indeed find out how to find the name of and address an existing text box.

I was also hpoing to display a smile or frown (from clipart images), by having the two images on the slide but invisible, and then making the appropriate image visible - but again I can't seem to find out how to address these images, never mind make one of them visible

So in summary
How do I call the sub when the slide appears ?
How can I put the text in the text box ?
How can I make an image visible ?

Thanks in anticipation
0
Comment
Question by:KCTS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
ID: 34942232
E bah gum tha dunt want much!


How do I call the sub when the slide appears ?
Assuming you are willing to add a button to initialise the event handler then:
See the snippet

How can I put the text in the text box ?
    If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex = 2 Then _
        Application.ActivePresentation.Slides(2).Shapes("TextBox 3").TextFrame.TextRange.Text = Now()

How can I make an image visible ?
    If ActivePresentation.SlideShowWindow.View.Slide.SlideIndex = 3 Then _
        Application.ActivePresentation.Slides(3).Shapes("Picture 3").Visible = True

Chris

'In a normal code module
Dim PPTClassObject As New Class1
Sub startup()
       Set PPTClassObject.PPTEvent = Application
End Sub

'In a new class module named as Class1 otherwise edit to replace!

Option Explicit

Public WithEvents PPTEvent As Application

Private Sub Class_Initialize()

End Sub

Private Sub Class_Terminate()
End Sub



Private Sub PPTEvent_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
    MsgBox "Displaying Slide " & ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34942336
As an aside ... to see what the shapes are called, select them on the slide then in the VBE immediate window type:

?activeWindow.Selection.ShapeRange(1).Name

ALso the startup either needs to be triggered manually or fired off a button in the presentation

AUto-open macros are possible but are a subject in their own right for PPT, (see http://skp.mvps.org/autoevents.htm for example)

Chris
0
 
LVL 23

Assisted Solution

by:JSRWilson
JSRWilson earned 250 total points
ID: 34942939
As Chris suggests PPT doesn't EASILY respond to events like Slide Change and you really need to use a class as he details.

Do you really need to do it that way though. When the final question is answered (some sort of button I guess0 just add code to update the final slide BEFORE you get there.

If TextBox1 is a control Text Box (And it shouldn't need to be!)

ActivePresentation.Slides(8).Shapes("Textbox1").OLEFormat.Object.Text = _
"your score was " + QScore + "out of " + QMax + ". Thank you"

Open in new window


If it's a normal shape (Better)

ActivePresentation.Slides(8).Shapes("Textbox1").TextFrame.TextRange = _
"your score was " + QScore + "out of " + QMax + ". Thank you"

Open in new window


For the images

ActivePresentation.Slides(8).Shapes("Picture 1").visible =True 

Open in new window


You don't need code to check the names of shapes from 2007 just open the Selection Pane
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 70

Author Comment

by:KCTS
ID: 34943060
Thanks to you both - I'm not at my normal machine right now - I'll give it a go when I get back

... it seemed to be such a straightforward to do ... until I tried to do it !
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 34943340
Let us know how you get on.

Selection Pane (a truly useful addition in 2007) is HOME tab >>Editing >>Select

You can use it to read the names AND change them to something more useful.
0
 
LVL 70

Author Closing Comment

by:KCTS
ID: 34970150
Thanks to you both - I have sucessfully implimented this and it works :-)

- good tip about the selection pane - I would have never found that.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PowerPoint is the go-to presentation software for millions of users around the world. Many presentations use basic text features but you can really make special text jump out of your slide by applying this bubble text design process. This article ha…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question