Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Use mouse location to place autoshape via VBA

I'm have a worksheet with an imported picture. I'm using the mouse X/Y
coordinates to identify specific points on the picture, which will be used in
calculating the location of autoshapes that will be placed with a later macro.

To make sure that I'm headed in the right direction, I set up my code to
move a small autoshape to the mouse location when I click on the picture. I'm
getting reliable X/Y coordinates, but the autoshape is not ending up where
the mouse is. (autoshape top/left = pox.y and pos.x)

At this point, it seems likely that the mouse X/Y is actual (anywhere on the
screen or toolbars) whereas the autoshape is maybe offset from the top left
of the worksheet(?).

I won't be the only user of this worksheet, and different users may have
different numbers of toolbars/menu/etc. What is the most reliable way to
identify the relative start point for an autoshape placement, and work
backward to my actual mouse X/Y coordinates?

Thank you,
Keith

Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Global PasteNow
Public MyX
Public MyY

Type POINTAPI
X As Long
Y As Long
End Type

Sub ShowPos()
PasteNow = False
Do Until (StopMe = True)
Dim lRetVal As Long
Dim Pos As POINTAPI
lRetVal = GetCursorPos(Pos)
Application.StatusBar = Pos.X & ", " & Pos.Y
Str1 = "1. " & Pos.X & ", " & Pos.Y
DoEvents
If PasteNow = True Then
UseCol = Chr(MyY + 65)
UseRow = MyX + 1
Sheet3.Range(UseCol & UseRow).Value = Pos.X
Sheet3.Range(UseCol & (UseRow + 10)).Value = Pos.Y
Debug.Print Str1 & " 2. " & Pos.X & ", " & Pos.Y
Sheet2.Shapes("Oval 2").Left = (Val(Pos.X))
Sheet2.Shapes("Oval 2").Top = (Val(Pos.Y) )
Debug.Print Sheet2.Shapes("Oval 2").Left & ", " &
Sheet2.Shapes("Oval 2").Top
PasteNow = False
End If
Loop
End Sub

Sub PictureClick()
UserForm1.Show
End Sub

{userform 1 has two text boxes and a submit button; these are values to help
me insert the X/Y coordinates onto a second sheet for permanent storage)}
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Place an autoshape alstubna Excel Programming 3 February 25th 08 07:25 PM
AutoShape Location Ronbo Excel Programming 0 November 17th 06 01:45 AM
mouse location dennis Excel Discussion (Misc queries) 1 July 25th 06 06:23 PM
Mouse Location, Movement and Spreadsheet Location TCook Excel Programming 3 October 3rd 05 10:23 PM
Mouse over effect on autoshape Mark Stephens Charts and Charting in Excel 1 May 7th 05 03:54 PM


All times are GMT +1. The time now is 05:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"