Is it possible? Draw an arrow where the mouse is pointing

mtheriault2000

Well-known Member
Joined
Oct 23, 2008
Messages
826
Hello again

Using the msoShapeLeftArrow, is it possible to add an arrow on my picture where the mouse is pointing

a) determine mouse position
b) send a command to draw an arrow

This sub called by a shortcut key

Nice concept, but no idea at all how to do it

Martin
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I scavenged some code from Jaafar Tribak's reply to this post, and came up with the following code. Put this in a standard Module. I assigned the shortcut CTRL + r, which I don't think is assigned anything else.

Code:
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
    x As Long
    Y As Long
End Type
Dim udtCursorPos As POINTAPI
Sub plant_arrow()
Dim xpos, ypos As Long
            
'\\ Get Mouse Pointer location in Screen Pixels
GetCursorPos udtCursorPos

'\\ Get Cell under Cursor
Set objcell = ActiveWindow.RangeFromPoint(udtCursorPos.x, udtCursorPos.Y)

'With objcell.Offset(0, 1)
'    xpos = .Left
'    ypos = .Top
'End With
xpos = objcell.Offset(0, 1).Left
ypos = (objcell.Top + objcell.Offset(-1, 0).Top) / 2

ActiveSheet.Shapes.AddShape(msoShapeLeftArrow, xpos, ypos, 119#, 25.5).Select
'                                             horiz  vert  long  thick
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
objcell.Select
End Sub

This places the left arrow on the right edge of the cell your mouse is over, roughly centered top to bottom, then fills it in with yellow. It's a fairly large arrow, taking up a full cell height and two-and-a-half cells wide with the default cell sizing on my computer. You can change the dimensions of the arrow by editing the 119# and the 25.5 figures, and change the color by editing the SchemeColor = 13 figure.
 
Upvote 0
Hello gardnertoo

Thanks for the reply.

I had resolved the problem. My quest was a little bit different as i wanted to place an arrrow over a jpeg picture.

I still have a problem with the precision, as my mouse does not point out exactly where the cursor was, but i could live with that and moved the arrow when necessary.

Martin
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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