PDA

View Full Version : How to get the cursor point location in a slide?



prshnthvn
06-05-2010, 10:56 AM
Hello All,

Can anyone let me know how to get the cursor point location in a slide?
I am writing a macro to place a Shape at user defined location in a slide, in the below code instead of 200# & 330# i want the "x" & "y" location of the cursor where the user intend to place the shape. Any help will be greatly appreciated.

Sub Macro1()
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, 200#, 330#, 42#, 42#).Select
ActiveWindow.Selection.ShapeRange.Fill.Visible = msoFalse
With ActiveWindow.Selection.ShapeRange
.Line.Visible = msoTrue
.Line.Style = msoLineThinThin
.Line.Weight = 3#
.Line.ForeColor.RGB = RGB(0, 0, 255)
End With
ActiveWindow.Selection.Unselect
End Sub

Thanks in advance,
Prashanth

John Wilson
06-06-2010, 04:46 AM
Not easy

You can use the GetCursorPos API but this relates to the screen. You would need to take account of the slide zoom factor and screen resolution as well as converting pixels to points

Code for screen

Private Declare Function GetCursorPos Lib "user32" (lpPoint As Point) As Long
Type Point
X As Long
Y As Long
End Type
Sub c_pos()
Dim CurMouseLocation As Point
GetCursorPos CurMouseLocation
MsgBox "X value = " & (CurMouseLocation.X) & " Y value= " & (CurMouseLocation.Y)
End Sub

Also how do you intend to start the code without moving the cursor?

prshnthvn
06-06-2010, 05:28 AM
Thanks for the reply john, the below code will give the current location of the cursor, Is there anyway that the macro stops until you click on slide so that it will take that X and Y location?

I want to place the shape where the user wants to place it on the slide. Here is the step in which the macro should run:

1. When Macro starts, I want to display a message box "Please click on the slide where you want to place the shape"
2. The macro should wait till the user clicks on a location.
3. When the user clicks, I can use your code to get the current location of the cursor and continue with the my code.

Thanks in advance,
Prashanth

fumei
06-14-2010, 01:14 PM
Get the user to place the cursor first, THEN execute the instructions.