PDA

View Full Version : Place textbox on pointer position in Word VBA



Thinus
03-16-2016, 07:39 AM
I want to place a textbox at the mouse pointer position on right click. I have the following code to get the coordinates:

Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
' Create custom variable that holds two integers
Type POINTAPI
Xcoord As Long
Ycoord As Long
End Type

Sub GetCursorPosDemo()
Dim llCoord As POINTAPI
' Get the cursor positions
GetCursorPos llCoord
' Display the cursor position coordinates
MsgBox "X Position: " & llCoord.Xcoord & vbNewLine & "Y Position: " & llCoord.Ycoord
End Sub
The textbox must be inserted on Xcoord and Ycoord, whether there is text or not.

I have the following:

With Box
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Left = InchesToPoints(3)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Top = InchesToPoints(3)
End With

How do I get the wdRelativeVerticalPositionPage and wdRelativeHorizontalPositionPage