【问题标题】:VBA PowerPoint Mouseout Technique Not Called未调用 VBA PowerPoint 鼠标悬停技术
【发布时间】:2019-05-10 21:26:15
【问题描述】:

我认为我在使用 powerpoint 宏时遇到了问题,这使我无法获得想要的行为。我正在尝试在 powerpoint 幻灯片中实现鼠标悬停/鼠标悬停效果。

这个想法被赋予了三个正方形,在悬停时独立改变每个的线条颜色......

悬停时形状线条变化

...然后在鼠标移出时将其恢复到原始状态。我知道 PP 不支持 mouseout,所以我尝试使用 the mouseout hack consisting of another shape with a mouseout macro mentioned here -

当鼠标悬停在背景形状上时形状线重置

我正在尝试使用以下宏来实现这一点。当鼠标在正方形上时触发 shapeHover()。 MouseOutHack() 应该在鼠标位于背景形状上时触发,但线条不会重置为其原始颜色。我的宏有问题吗?两者都在同一个模块中。

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

【问题讨论】:

  • 我认为在Sub MouseOutHack() 中您可以使用With myShape 而不是With oShpmyShape 曾经被设置为使用Sub shapeHover(oShp As Shape) 修改的最后一个形状。也无需使用oShp.Line.....,因为您正在使用 with。只有.Line.... 就足够了。

标签: vba powerpoint mouseout


【解决方案1】:

正如 Ahmed AU 所说...在 MouseOutHack 中使用 myShape 并利用 With 语句,如果您要使用它们...然后它就会起作用。

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

【讨论】: