Mouse Hover

Hi Experts

Using VBA in PowerPoint, how can I achieve a Mouse Hover effect, so when the user moves the mouse over a button it changes color, then when it moves it out it changes another color?  Is this the MouseDown event, using the X & Y values?

Also, colors such as &H00FFFFFF& - are these hexadecimal? If no, can they be or RGB?

Thank you.
APD TorontoSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
MSDN.... Action buttons are built-in button shapes (located in the Shapes gallery) that you can add to your presentation, and then assign an action to occur when you click ...

indicates you can add an action to MouseOver. But changing colors is not one of them , though maybe able to add a suitable VBA action if you can determine the calling shape.

        Sub Identify( oShp as Shape)

        Msgbox oShp.Name, vbInformation+vbOkOnly

        End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
What you describe is not MouseHover, it would be MouseEnter and MouseLeave.

MouseHover is when the mouse is floating over a control without moving, in contrast with MouseMove, which is triggered when the mouse is moving over a control. These 2 events are triggered repetitively at short interval while the condition is true.

Unfortunately, VBA in Office is very limited and does not offer MouseHover, MouseEnter and MouseLeave.

The only event that could be used for what you intend to do is MouseMove.

But there are 2 problems with that. First, it triggers continuously while the user moves the mouse over the control. So in some situations, the screen could flicker if there is too much code in the event. I do not think that it would be a problem with simply changing the color however.

The second problem is the worst. There is absolutely no way to know when to revert to the regular color. The controls offered with Office are not meant to create sophisticated user interfaces. They are simply too limited for your purpose.

Yes, &H00FFFFFF (you have an extra & at the end however) is hexadecimal. You can use it as is to define a color... as long as you know the value for the color that you seek.
APD TorontoSoftware DeveloperAuthor Commented:

Expanding on your code, I'm trying the folowing, but nothing is happening

Sub hoverCalculate(oShp As Shape)

    oShp.Fill.BackColor.RGB = RGB(255, 0, 0)

End Sub

Open in new window

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

APD TorontoSoftware DeveloperAuthor Commented:
Sorry, should've used ForeColor, which works.  However, what about reversing it back on MouseOut
APD TorontoSoftware DeveloperAuthor Commented:
@James, there will be only 4 lines of code if I use MouseMove, and there are Top and Left properties of the object.  Isn't MouseMove viable?
Jacques Bourgeois (James Burger)PresidentCommented:
Yes, you could always try it, but it will be more than 4 lines of code.

The thing is that you cannot know from which side the user will be entering. Same thing for the exit.

And you cannot simply check for the values of 0, button width and button height to determine if the cursor is on a border. I cannot say for Office, because I never had to use MouseMove with Office, but in other environments, MouseMove trigger on a timer instead of on the pixels. Many pixels can be skipped between 2 MouseMoves, so the first MouseMove for a cursor entering the control top might be at 1, 2 or 4, maybe more. You would have to test to see the amount of pixels you should consider around the control.

It will also be hard, to determine when the user is getting out, many situations will have to be considered.

Say that the user enter from the Left on a MouseMove at 4, then suddenly moves back out of the control. You will get only the Enter and will not be able to detect the exit. You need at least 2 MouseMove in order to detect both entry and exit.

Then, think of a user that moves horizontally very close to the top. You will get a series of Top positions that could oscillate between, let's say, 2 and 4 because the user is just a bit shaky. How will you know, in the sequence 2233432342, that the last 2 is the one getting you out of the control?

In my opinion, doing it with the MouseMove can work most of the time if properly done, but there will be many situations in which you won't be able to detect the mouse getting out.

For a user, nothing is annoying as erratic behavior.

One idea that I have while writing this. Playing with events often asks for creative ways to fix things.

Behind your Button, put a Label that is larger than the Button and make it the same color as the background, so that it does not show. When the user gets out of the Button, the Label will start receiving MouseMove. This is your indication that the cursor is out and that the Button should get back to normal.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.