How to Display Tooltip on Mouseover Using VBA in Excel

Get FREE Advanced Excel Exercises with Solutions!

Sometimes you might want to know information before clicking on anything in Excel. You can do it by adding a tooltip to a text, shape, and image that will be visible when you hover your mouse over them. In this article, we will show you how to display tooltip on mouseover using VBA in Excel using 3 examples.


How to Display Tooltip on Mouseover Using VBA in Excel: 3 Suitable Examples

In this article, we will demonstrate 3 suitable examples to display tooltips for text, shapes, and images on mouseover using VBA in Excel. We will use the following dataset for this purpose.

How to Display Tooltip on Mouseover Using VBA in Excel


Example 1: Use VBA Code to Display Tooltip on Mouseover for Text

In this example, we will show you how to display the tooltip on the mouseover for text. We will follow these next steps for this purpose.

Steps:

  • First, we want to display tooltips for the Sales Rep To do it, press  Alt+F11 .

Use VBA Code to Display Tooltip on Mouseover for Text

  • It will open the Microsoft Visual Basic window.

  • Next, click on Module under the Insert tab.

  • Module 1 (Code) window will appear. Copy the following VBA code from below and paste it into the window.
Sub Text()
Dim x As Range
 For Each x In Range("B5:B9")
    With x.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, _
            Operator:=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputMessage = "First Name of Sales Rep"
        .ShowError = True
    End With
Next x
End Sub
 
			

Use VBA Code to Display Tooltip on Mouseover for Text

  • In this code, we wrote the Input Message “First Name of Sales Rep”. You can type your desired message here.
  • Now press  F5   to run the code and go back to your Excel worksheet and click any one of the Sales Rep The Input Message will appear as a tooltip.

Use VBA Code to Display Tooltip on Mouseover for Text


Example 2: Apply VBA Code to Display Tooltip on Mouseover for Shapes

Now you will see a VBA code to display the tooltip on mouseover for shapes. Keep on reading to learn the steps.

Steps:

  • First of all, select the shape and click the right button on your mouse.
  • Then click on Assign Macro.

 Apply VBA Code to Display Tooltip on Mouseover for Shapes

  • A pop-up box will open. Now click on New.

  • A new window to write code will appear.

  • Next, type the following code in that window to assign the shape to a macro.
Sub Star5Points1_Click()
If Target.Address = Range("C5").Address Then
        Call Star5Points1_Click
    End If
End Sub

			

 Apply VBA Code to Display Tooltip on Mouseover for Shapes

  • Now insert another Module from the Insert tab.

 Apply VBA Code to Display Tooltip on Mouseover for Shapes

  • After that, copy-paste the following formula into the window.
Sub Shape()
    Dim x As Shape
    Dim y As Range
    On Error Resume Next
    Application.EnableEvents = False
    Set x = ActiveSheet.Shapes("Star: 5 Points 1")
    If Not x Is Nothing Then
        ActiveSheet.Hyperlinks.Add x, "", "C5", ScreenTip:="Display Tooltip for shape"
    End If
    If ActiveSheet.Hyperlinks(1).SubAddress = "C5" Then
        Call Star5Points1_Click
    End If
    Application.EnableEvents = True
End Sub 
			

 Apply VBA Code to Display Tooltip on Mouseover for Shapes

  • Finally, press  F5  to run the code.
  • In the worksheet, hover your mouse over the shape and the tooltip will be visible.

 Apply VBA Code to Display Tooltip on Mouseover for Shapes

Read More: How to Create Dynamic Tooltip in Excel


Example 3: Run an Excel VBA Code to Display Tooltip on Mouseover for Image

We can also display the tooltip for images by running the VBA code. Follow the next steps to learn how to do it.

Steps:

  • First, Go to the Insert tab and click on Shapes.
  • Then select Rectangle.

  • Your cursor will look like a “+” sign. Drag your cursor to create a shape around your image.

  • The shape will have a default fill color. To remove the color, right-click on the image and select Fill.

Run an Excel VBA Code to Display Tooltip on Mouseover for Image

  • Then click on No Fill to make the image visible inside the shape.

  • Now double-click inside the shape. It will open a window to write code.
  • Next, write down the following code there.
Sub Image()
If Target.Address = Range("C5").Address Then
        Call Image
End Sub 
			

Run an Excel VBA Code to Display Tooltip on Mouseover for Image

  • After that, insert another Module from the Insert tab and copy-paste the following formula there.
Sub Image()
    Dim x As Shape
    Dim y As Range
    On Error Resume Next
    Application.EnableEvents = False
    Set x = ActiveSheet.Shapes("Rectangle 3")
    If Not x Is Nothing Then
        ActiveSheet.Hyperlinks.Add xShape, "", "C5", ScreenTip:="Display Tooltip for Image"
    End If
    If ActiveSheet.Hyperlinks(1).SubAddress = "C5" Then
        Call Image
    End If
    Application.EnableEvents = True
End Sub 
			

Run an Excel VBA Code to Display Tooltip on Mouseover for Image

  • Finally, press  F5  to run the code and go back to the Excel sheet.
  • Now if you hover your cursor over the image, it will show your desired tooltip.

How to Display Tooltip on Mouseover Using VBA in Excel


Notes
  • Remember to write the tooltip in the code, you want to show while hovering over the text, shape, or image.
  • Assign the shape before running the VBA code, otherwise, the code will not run.

Read More: How to Add Tooltip to UDF in Excel


Download Practice Workbook

Download this practice workbook for practice while you are reading this article.


Conclusion

Thanks for making it this far. I hope you find this article useful. Now you know 3 examples to display the tooltip on mouseover using VBA in Excel. Please let us know if you have any further queries and feel free to give us any recommendations in the comment section below.


Related Articles

Alif Bin Hussain
Alif Bin Hussain

Hello! Welcome to my Profile. Currently, I am working and doing research on Microsoft Excel and here I will be posting articles related to this. My last educational degree was BSc and my program was Civil Engineering from Bangladesh University of Engineering & Technology (BUET). I am a fresh graduate with a great interest in research and development. I do my best to acquire new information and try to find out the most efficient solutions.

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo