Hover effect

Creating mouse hover effect in excel VBA userform #

Take #1 #

When did VB6—the foundation of VBA—officially lose technical support? It’s quite unfortunate that one of the few programming languages familiar and accessible to non-developers and marketers at work is based on technology from decades ago.

Compared to today’s technologies, it might be natural that it shows its limitations. Today, I’m attempting a workaround to implement a mouse hover effect on an object used as a button.


Take #2 #

Create image pairs for default and hover states. Since changing colors later requires regenerating all images, you need to choose carefully. Overlay the two images: place the hover image on top with its Visible property set to False, and the default image underneath.

Then, place a transparent label covering the entire page background. Using the MouseMove event on the default image, set the hover image’s Visible to True on mouse over.

Finally, use the MouseMove event on the transparent label to set the hover image’s Visible back to False when the mouse moves away.


Take #3 #

button - over

Private Sub btn1_1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  btn1_1.Visible = False
  btn1_1_2.Visible = True
End Sub

  button - out

Private Sub transparent_bg0_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  btn1_1.Visible = True
  btn1_1_2.Visible = False
End Sub

 
original post (Kor)