Search code examples
vbapowerpointmouseout

VBA PowerPoint Mouseout Technique Not Called


I believe I have a problem with powerpoint macros that is keeping me from getting my desired behavior. I'm attempting to achieve a mouseover/mouseout effect in a powerpoint slide.

The idea is given three square shapes, change the line color of each independently on hover...

shape line changes on hover

shape line changes on hover

...then return it to its original state on mouseout. I know PP doesn't support mouseout, so I'm attempting to use the mouseout hack consisting of another shape with a mouseout macro mentioned here -

shape lines reset when mouse is over background shape

shape lines reset when mouse is over background shape

I'm trying to use the following macros to achieve this. shapeHover() is triggered when the mouse is on a square. MouseOutHack() is supposed to be triggered when the mouse is on the background shape, but the lines are not resetting to their original color. Is there a problem with my macros? Both are in the same module.

Option Explicit

Public myShape As Shape ' Global reference to mouse over shape

Sub shapeHover(oShp As Shape)
  Set myShape = oShp
  With oShp
    ' Change the properties you need here
    oShp.Line.ForeColor.RGB = RGB(0, 0, 0)
  End With
End Sub

Sub MouseOutHack()
  With oShp
    ' Reset the properties you need here
    oShp.Line.ForeColor.RGB = RGB(255, 0, 0)
  End With
End Sub

Solution

  • As Ahmed AU said ... use myShape in MouseOutHack and leverage the With statements if you're going to use them ... and then it'll work.

    Option Explicit
    
    Public myShape As Shape ' Global reference to mouse over shape
    
    Sub shapeHover(oShp As Shape)
      Set myShape = oShp
      With oShp
        .Line.ForeColor.RGB = RGB(0, 0, 0)
      End With
    End Sub
    
    Sub MouseOutHack()
      With myShape
        .Line.ForeColor.RGB = RGB(255, 0, 0)
      End With
    End Sub