PowerPoint VBA Macro Mouse Over and Mouse Out - vba

I want to apply trigger animation when mouse over
I found very helpful tutorial so I can make the animation happen when mouse Over the button, but it allow the animation to happen only when the mouse come over the button again
What I need is to the required animation happen as below:
- when mouse over the button, the image appears
- when mouse out the button, the image disappears
(with no need to mouse re-over again the shape button)
Can someone help me achieve that.
here is the VBA code which in the tutorial,
Sub anim(oshp As Shape)
Dim osld As Slide
Set osld = oshp.Parent
'Note alter the name here to match the trigger shape
If osld.Shapes("Rectangle 7").ZOrderPosition = 1 Then
SendKeys ("{TAB}")
SendKeys ("{ENTER}")
Else
osld.Shapes("Rectangle 7").ZOrder (msoSendToBack)
End If
End Sub

Related

When slide 5 is displayed change slide transition properties on slide 1

I have a presentation that slide 1 .AdvanceOnClick = msoTrue. This is so after the slide show starts, it waits for mouse click before advancing (want slide 1 to display and wait for mouse click).
After the initial mouse click to start advancing, for example on slide 5, I want to change the .AdvanceOnClick to msoFalse on Slide 1 so the second and subsequent loops auto progress without user intervention. Basically, I want to change the Slide 1 transition properties when the presentation advances to, for example, slide 5.
I have tried the following code, which works fine, but I can't run this code from a different slide;
With ActivePresentation.Slides(1).SlideShowTransition
.AdvanceOnClick = msoTrue
.AdvanceOnTime = msoTrue
.AdvanceTime = 5
End With
Set the presentation to loop without the pause after slide 1.
Create a separate presentation consisting of only slide 1.
Hyperlink that to slide 2 of the looping presentation.
Now slide 1 will display until you click the hyperlink. Once you click, the presentation will loop without stopping. No VBA required.
If you need only one ppt file for some reason then you'll have to use VBA, I believe. This code works just fine only if you use something (a shape) in slide 5 and assign a Mouse Click Action to it to link to slide 1. It doesn't work if you go back to slide 1 using the keyboard arrows or the mouse wheel.
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
If SSW.View.CurrentShowPosition = 5 Then
With ActivePresentation.Slides(1).SlideShowTransition
.AdvanceOnClick = msoTrue
.AdvanceOnTime = msoTrue
.AdvanceTime = 5
End With
End If
End Sub

How to end a Powerpoint slideshow while staying on the current/active slide?

I'm looking for the opposite of the "Alt+F5" shortcut (Start a presentation from the current slide) as I have a very large presentation with many slides and want to be able to edit them quickly.
Currently, the "end show" action button I've set-upped (or the "ESC" shortcut) brings me back to my first slide.
I've managed to assign the following macro to a "stop" button, but this asks me to have as many lines as there are slides.
Sub ExitSlide3()
Application.SlideShowWindows(1).View.Exit
With Application.ActiveWindow
.ViewType = ppViewSlide
.View.GotoSlide 3
End With
End Sub
Using Insert>Action>Run macro, assign this to a shape, then copy the shape to each slide. The shape can be the same color as the background if you want it to be unobstrusive:
Sub ExitSlide()
ActivePresentation.SlideShowWindow.View.Exit
End Sub

Macro to change Shape Colour on Mouse Hover in PowerPoint

Is it possible to change the shape color on mouse hover using VBA in PowerPoint?
I tried creating the same effect using animations+trigger but it requires a click. However I would like to change the shape color as I hover the mouse over it and change it back to the original color as I hover the mouse to next shape. Is this possible to achieve?
Thanks in advance.
This is possible with a hack approach to overcome the fact that PowerPoint doesn't support the mouse-out event. What you can do is write a mouse-over macro as follows to change the colour:
Option Explicit
Public myShape as Shape ' Global reference to mouse over shape
Sub MouseOver(oShp As Shape)
Set myShape = oShp
With oShp
' Change the properties you need here
End With
End Sub
Assign that to your shape via Insert / Action / Mouse Over / Run Macro
Next, and this is the hack for no mouse-out event, add a rectangle shape to your slide on the bottom layer. Set the fill transparency to 100% and assign the following macro to it's mouse-over event:
Sub MouseOutHack()
With myShape
' Reset the properties you need here
End With
End Sub
Now, when you move the mouse over your shape, it's properties will change and when you move it out of the shape, the invisible background shape will trigger the resetting of the properties you choose.

How do I tell where the insertion point is in the Slides pane?

In PowerPoint, in "normal" view, the window is split into two panes, with a pane showing slide thumbnails on the left, and a pane showing the current slide on the right. You can select more than one slide in the left-hand panel, which is useful if you want to copy, move or delete slides.
To tell which slide(s) are currently selected in the left-hand panel, you can use ActiveWindow.Selection.SlideRange. However, if you click between slides in the left-hand (thumbnail) panel, you end up with an insertion point, and:
ActiveWindow.Selection.Type is zero (ppSelectionNone).
ActiveWindow.Selection.SlideRange gives an error.
I have a question in two halves:
How can I detect this situation? (Presumably there are other cases where the selection type is "none").
How can I tell where the insertion point is, so that I can insert new slides at that point?
Either VBA or VSTO code would be fine :-)
Answer to the first question:
' The mouse cursor can be placed between slide thumbnails in the following views:
' - Normal View / Thumbnail Pane
' - Slide Sorter View
' - Slide Master View / Thumbnail Pane
' Returns true if the cursor is in the slide gap in these cases.
Function IsSlideGap() As Boolean
On Error Resume Next
With ActiveWindow
Select Case .View.Type
Case ppViewNormal, ppViewSlideMaster
' If the thumbnail pane (ViewType 11 or 12 ) is active but
' nothing is selected, we must be in the slide gap
If .Panes(1).Active And .Selection.Type = ppSelectionNone Then IsSlideGap = True
Case ppViewSlideSorter
If .Selection.Type = ppSelectionNone Then IsSlideGap = True
End Select
End With
End Function
Answer to second question:
' Note: used by slide/gap context menus only so assumes
' either thumbnail pane or sorter view active
Function GetSlideCursorIndex() As Long
Dim lSlides As Long ' Track the number of slides in order
' to check if the temporary slide was deleted.
Dim oSld As Slide
lSlides = ActivePresentation.Slides.Count
' Insert a temporary new slide
CommandBars.ExecuteMso "SlideNew"
DoEvents
Set oSld = ActiveWindow.View.Slide
With oSld
GetSlideCursorIndex = .SlideIndex
.Delete
End With
If ActivePresentation.Slides.Count <> lSlides Then Debug.Print "Something went wrong!"
End Function
I just found this: http://skp.mvps.org/pptxp020.htm
Summary: switch to ppViewSlide view and then back again, and PowerPoint will select the slide before the insertion point (or the first slide, if the IP is at the start).
I'd still be interested in a better way that avoids the screen flicker inherent in this approach (and ideally does not change the selection).

Animate a gif in Powerpoint when the mouse cursor is over it

I was wondering if there was any way that I could write in Powerpoint 2010 VBA a small program that animates a gif when a mouse cursor is hovered over it.
Not exactly, but you can write a macro that makes one picture visible when you mouse over another shape.
So add a shape of any sort, it might be a non-animated version of the animated gif, for example. Assign it an Action setting on mouseover of Run Macro: ShowMe
First, add this to your presentation:
Sub ShowMe()
' Edit this to change the slide number as needed and to
' change "Picture 1" to the actual name of the animated gif
ActivePresentation.Slides(1).Shapes("Picture 1").Visible = True
End Sub
Then use the selection pane to make the animaged gif invisible.
You could put a slightly larger shape behind both of these shapes and set its mouseover action to the macro HideMe, which is the same as ShowMe but set .Visible = False
When the cursor hovers over the ShowMe trigger shape, the anigif becomes visible; when the cursor moves off the gif, it falls on the HideMe shape which triggers the second macro and hides the GIF again.