cusor position in sheet? no problem - but if there's an image?

SeniorNewbie

Board Regular
Joined
Jul 9, 2023
Messages
77
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
  2. MacOS
sorry cursor ...

Hi out there,
the following code (provided my MS) makes is easy (e.g. by double click event) to get the coordinates of a cursor in a worksheet:
VBA Code:
Option Explicit

Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
' Access the GetCursorPos function in user32.dll
Declare Function SetCursorPos Lib "user32" _
(ByVal x As Long, ByVal y As Long) As Long

' GetCursorPos requires a variable declared as a custom data type
' that will hold two integers, one for x value and one for y value
Type POINTAPI
   X_Pos As Long
   Y_Pos As Long
End Type

' Main routine to dimension variables, retrieve cursor position,
' and display coordinates
Sub Get_Cursor_Pos()

' Dimension the variable that will hold the x and y cursor positions
Dim Hold As POINTAPI

' Place the cursor positions in variable Hold
GetCursorPos Hold

' Display the cursor position coordinates
MsgBox "X Position is : " & Hold.X_Pos & Chr(10) & _
   "Y Position is : " & Hold.Y_Pos
End Sub

But what I need is this information on top of an image. As example: the image is map and I want to get more information about a region clicking on it. The're about 65 spots I need and I want o avoid to play around with shapes.
Any ideas about a solution?

Many THX!

Senior Newbie
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Not easy. Conceptually, you could first cache each spot screen location (x,y) relative to the image top left corner. Then, after that, you could have code to track the cursor position when the mouse is moved over the image and check if it is over any of those spots. If it is , run code to display the info related to the hovered spot.

Is the image embedded in a worksheet? And if so, what kind of image is it ? Is it an ActiveX image that supports mouse move events or is it some other kind of shape ?
 
Upvote 1
Hi Jaafar,
while I was waiting for a reply from here I started, what i wanted to avoid: kidding around with shapes ... So I found that there's an easy way to define just spots as a shape and relate it to a sub.
Thank you anyway for your comment, showing me that sometimes VBA ist not the best language to solve silly ideas ;)

Enjoy the weekend! and THX
I'll keep on shaping ;)
Senior Newbie
 
Upvote 0
Would you be willing to share your solution for people that are looking for an answer to the same or similar problem, just like you were looking for help?
 
Upvote 0
Hi jolivanes,

my answer is quite simple: Of course I'll share solutions! But - sorry: Mine is a very stupid one:

I'm adding shapes by a loop, named by an array. The coordinates for these shapes are taken from a sheet. Then all shapes are attached to a procedure which reacts on characters in the name of the shape. Shape's name "A_123" means: hand over the value 123 to sub A. Simply separated by left/right, controled by Select Case

My next challange is to create an algorithm to push the shapes to the right position. So far I'm setting the coordinates manually.

Hope it helps anyway ;)

If there's a better solution I'll let the people know - promised!

Best wishes! Senior Newbie
 
Last edited:
Upvote 0
Your willingness to show your solution is very much appreciated but I am afraid that it is as clear as mud to another "Newbie", Senior or Junior.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top