
Tips.Net > ExcelTips Home > Graphics > ScreenTip for an Image
Summary: You can configure images in Excel so that if someone clicks on them, a macro is executed. You cannot, however, have a macro and a traditional ScreenTip tied to the same object. This tip explains how you can get around this limitation using two separate techniques. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
Eddie has added a small graphic image to a worksheet and tied a macro to the image. When the image is clicked, the macro is executed. Eddie wonders if it is possible to add a label or comment to the image so that when a user hovers the mouse pointer over the image, the label/comment appears and tells the user what the macro does.
You might at first think that you could add a ScreenTip to the image, but that can only be done if you assign a hyperlink to it. Adding the hyperlink (and ScreenTip) is easy enough, but you'll find that the hyperlink takes precedence over the macro, stopping it from being run.
This means that you need to look for other ways to tackle the problem. Unfortunately there is no easy way to create this type of ScreenTip, but there are a couple of ways you can approach the task. One thing you can do is to add a command button to the worksheet, and then assign the image to the button. The whole image then serves as a button. When you click the button, it executes the CommandButton1_Click event handler (assuming you use the default name for the command button).
Next you need to create a text box that approximates what a ScreenTip looks like. Actually the text box gives you more latitude than you have with a regular ScreenTip, because it can be formatted in any manner you desire, and it can contain any explanatory text you desire. All you need to do is make sure that the text box is given a unique name, such as "MyShape". (You assign a name to the text box by selecting it and then changing the name in Name box in the upper-left corner of the worksheet area.)
With the command button and text box in place, right-click on the command button and choose to display the code window for the command button. Then, add the following code to the code window:
Private Sub CommandButton1_Click()
'Call your regular macro here
Hide_Shape
End Sub
Private Sub CommandButton1_MouseMove( _
ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Display_and_Hide_Shape
End Sub
It is the Click event handler that you will need to modify to call your normal macro code. The MoueMove code is executed when the mouse is moved over the command button. In this case, the code displays the text box you created.
Next, insert the following macros into a standard macro module. These two macros show and hide the text box shape that you created. Note that the first macro uses the OnTime method to automatically hide the shape two seconds after it is first displayed.
Sub Display_and_Hide_Shape()
ActiveSheet.Shapes("MyShape").Visible = True
' adjust time
Application.OnTime Now + TimeValue("00:00:02"), "Hide_Shape"
End Sub
Sub Hide_Shape()
ActiveSheet.Shapes("MyShape").Visible = False
End Sub
With all the macros in place, just move the mouse pointer over the command button image. The text box should disappear two seconds later, only to reappear when you again move the mouse over the image.
Another approach is to embed the picture in a chart object, name the picture using whatever text you want to appear in the ScreenTip, and then assign the macro to the chart object. This may sound a bit confusing, but it is relatively easy to do by following these general steps:
That's it. Now, when you move the mouse pointer over the image, the name of the image appears as a ScreenTip, and if you click then the macro assigned to the chart object is executed.
Tip #3294 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Got the Time? If you work with either times or dates in Excel, you really need ExcelTips: Times and Dates. Everything you need to know about slicing, dicing, and generally working with times and dates.
Have thousands of ExcelTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site