Action buttons

A

Anne

I've been trying to use a PowerPoint action button to run a macro, but even
though I've selected the appropriate option on the action settings menu
absolutely nothing happens. The hyperlink option works, but it seems as if
the button simply isn't connected to the 'run macro' option - I won't run
even the simplest keystroke macro from an action button. I've tried all the
obvious things like re-setting the security (at least I think I've tried all
the obvious things, I must admit I shan't be the least bit surprised if it
turns out that I've missed something blindingly obvious) so if anyone can
shed any light in my darkness I will be eternally grateful.
 
A

Anne

You're more than welcome to pull my code to pieces (see below), but if it was
just that I'd expect some kind of error message/crash when I tried to run it
from the action button - at the moment it feels rather like pushing a
doorbell that isn't wired up!

Thanks.


'Define variables
'
Dim questCounter As Integer
Dim numIncorrect As Integer
'
'Set variables and show first question slide
'
Sub initialise()
numIcorrect = 0
questCounter = 4
ActiveWindow.Selection.Unselect
ActivePresentation.Slides.Range(Array(4)).Select
End Sub
'
'Increment incorrect answer counter
'and run appropriate sub routine
'
Sub mistake()
numIncorrect = numIncorrect + 1
If numIncorrect = 1 Then
onewrong
End If
If numIncorrect = 2 Then
twowrong
End If
If numIncorrect = 3 Then
threewrong
End If
End Sub
'
'Display slide for one wrong answer
'
Sub onewrong()
With ActivePresentation.Slides(4) _
.Shapes(1).ActionSettings(ppMouseClick)
..Action = ppActionRunMacro
End With
ActiveWindow.Selection.Unselect
ActivePresentation.Slides.Range(Array(18)).Select
End Sub
'
'Display slide for two wrong answers
'
Sub twowrong()
ActiveWindow.Selection.Unselect
ActivePresentation.Slides.Range(Array(19)).Select
End Sub
'
'Display slide for three wrong answers
'
Sub threewrong()
ActiveWindow.Selection.Unselect
ActivePresentation.Slides.Range(Array(20)).Select
End Sub
'
'Increment question counter
'and display next question
'
Sub nextQuest()
questCounter = questCounter + 1
ActiveWindow.Selection.Unselect
ActivePresentation.Slides.Range(Array(questCounter)).Select
End Sub
 
J

John Wilson

I'm surprized that you get no error messages.

Your code won't run in show mode (you are in show mode? Action buttons don't
do anything in edit mode)

The main problem is the use of ActiveWindow.Selection

You cannot have a selection in show mode and the code will always fail.

You will need to find a way to reference the shape along the lines of
ActivePresentation.Slides(2).Shapes(2)

To be honest I can't really see what you are trying to do with the rest of
the code. To goto a specific slide try
ActivePresentation.SlideShowWindow.View.GotoSlide(x)


--
Amazing PPT Hints, Tips and Tutorials

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

John Wilson

Maybe this is the sort of thing?

'Define variables

Dim questCounter As Integer
Dim numIncorrect As Integer

'Increment incorrect answer counter
'and run appropriate sub routine

Sub mistake()
numIncorrect = numIncorrect + 1
If numIncorrect = 1 Then ActivePresentation.SlideShowWindow _
..View.GotoSlide (18)

If numIncorrect = 2 Then ActivePresentation.SlideShowWindow _
..View.GotoSlide (19)

If numIncorrect = 3 Then ActivePresentation.SlideShowWindow _
..View.GotoSlide (20)

End Sub


'Increment question counter
'and display next question

Sub nextQuest()
questCounter = questCounter + 1
ActivePresentation.SlideShowWindow.View.GotoSlide (questCounter)
End Sub



Note you also have a spelling mistake in the initialization numIcorrect (n
missing)
--
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

In addition to John's excellent advice, I'm wondering what you're doing
with:

Sub onewrong()
With ActivePresentation.Slides(4) _
.Shapes(1).ActionSettings(ppMouseClick)
..Action = ppActionRunMacro
End With
ActiveWindow.Selection.Unselect
ActivePresentation.Slides.Range(Array(18)).Select
End Sub


You seem to be setting a button to have the action to run a macro, but
you don't specify which macro to run. If you want to do this, you
probably need to add

..Run = "<name of macro>"

right before the End With statement to tell the button which macro to
run.

--David
 
A

Anne

Thank you both for your help, although I've no doubt you're right about the
code (my programming experience is all with mainframe languages and I had
enormous difficulty finding any information about visual basic specific to
PowerPoint) changing it hasn't made any difference to my problem. When I try
to use any of the action buttons in show mode nothing happens - no error
messages, no crashes, nothing! It's as if there's no connection between the
button and the macro, so it seems reasonable to assume that there's some
problem quite independent of any inadaquacies in my code.

Am I missing something blindingly obvious in the way I'm trying to set the
buttons up? I've asked various friends and colleagues to take a look and none
of them have been able to get an action button to run a macro either, so
anything you can suggest to stop us all feeling like complete muppets would
be gratefully received.

Anne
 
J

John Wilson

Anne
Assuuming that you took on board the statement "Action buttons only work in
show mode" then you are welcome to email me a sample presentation and I'll
see if I can spot what's wrong. Your code should definitely trigger errors.
-- email john AT SIGN technologytrish.co.uk
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
 
D

David M. Marcovitz

You are right. There are very few resources for VBA in PowerPoint. In
addition to John's generous offer, I suggest that you visit my Web site,
which provides several examples of using VBA in PowerPoint:

http://www.PowerfulPowerPoint.com/

--David
 

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