在 PowerPoint 中鼠标悬停时更改形状颜色的宏 [英] Macro to change Shape Colour on Mouse Hover in PowerPoint

查看:83
本文介绍了在 PowerPoint 中鼠标悬停时更改形状颜色的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 PowerPoint 中使用 VBA 更改鼠标悬停时的形状颜色?

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?

提前致谢.

推荐答案

这可以通过一种黑客方法来克服 PowerPoint 不支持鼠标移开事件这一事实.您可以做的是编写如下的鼠标悬停宏来更改颜色:

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

接下来,这是无鼠标移开事件的技巧,在底层的幻灯片中添加一个矩形形状.将填充透明度设置为 100% 并将以下宏分配给它的鼠标悬停事件:

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.

这篇关于在 PowerPoint 中鼠标悬停时更改形状颜色的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆