问题
I am trying to insert a shape in a position of cursor where user click by an event WindowBeforeDoubleClick, but when I use the code below its relate to screen coordinate so it is not placing in word page properly.
can anyone suggest how to find the page margin coordinate or any other in order to place the shape at cursor point in word.
This is the code
Public Sub addWin()
ActiveDocument.Shapes.AddShape(msoShapeRectangle, MouseX, MouseY, 20#, _
16#).Select
Selection.ShapeRange.Name = "WK# " & 2
Selection.ShapeRange.TextFrame.TextRange.Select
Selection.Collapse
Selection.Font.Name = "Arial"
Selection.Font.Size = 7
Selection.Font.Bold = False
Selection.Paragraphs.FirstLineIndent = 0
Selection.Paragraphs.RightIndent = -10
Selection.Paragraphs.LeftIndent = -10
Selection.Paragraphs.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:=2
Selection.ShapeRange.LockAspectRatio = msoCTrue
End Sub
Function MouseX(Optional ByVal hWnd As Long) As Long
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
If hWnd Then ScreenToClient hWnd, lpPoint
MouseX = lpPoint.x
End Function
Function MouseY(Optional ByVal hWnd As Long) As Long
Dim lpPoint As POINTAPI
GetCursorPos lpPoint
If hWnd Then ScreenToClient hWnd, lpPoint
MouseY = lpPoint.y
End Function
来源:https://stackoverflow.com/questions/59402917/how-to-insert-shape-in-cursor-position-when-user-clicks