Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Adding a Little Animation to Your Life
Converting a Range of URLs to Hyperlinks
Making the Formula Bar Persistent
Gerald notes that when moving the mouse over a picture on a worksheet the mouse pointer is a cross. He wants to know how he can determine, using VBA, the coordinates of the cross when the mouse is clicked.
Excel doesn't allow you (even with VBA) to get the coordinates of the mouse pointer on a graphic inserted as a regular picture in the worksheet. If you insert the picture using an Image object in the Control toolbox, you have quite a bit more latitude. Indeed, you can use the MouseDown event handler to determine the coordinates, as shown here:
Private Sub Image1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
MsgBox X & ", " & Y
End Sub
This code assumes that the image is named Image1. Similar code could be used to display the cursor coordinates in real time on the status bar:
Private Sub Image1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
Application.StatusBar = Round(X, 0) & "," & Round(Y, 0)
End Sub
Either (or both) of these event handlers are obviously associated with Image1, so they need to be added to the code window for that object.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3421) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Change Formatting Based On Your Data! Conditional formatting provides a way for you to adjust the appearance of your data based on the data itself. Discover how to put this amazingly powerful feature to work for you, today. This comprehensive volume is available in two editions.