Place Text box at Mouse Pointer Position on a page

Joined
Mar 18, 2016
Messages
1
Reaction score
0
I want to insert a Text box at the Mouse have the following to determine the position of the pointer:

Code:
    Dim llCoord As POINTAPI
    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 GetCursorPosition()
         'Get the cursor positions
        GetCursorPos llCoord
         'Display the cursor position coordinates
        MsgBox "X Position: " & llCoord.Xcoord & vbNewLine & "Y Position: " & llCoord.Ycoord
    End Sub

To insert the Text Box I have:

Code:
Sub mark()
    Dim Box As Shape
    Set Box = ActiveDocument.Shapes.AddTextbox( _
        Orientation:=msoTextOrientationHorizontal, _
        Left:=25, Top:=25, Width:=25, Height:=25)
        Box.Line.Visible = msoFalse
        Box.TextFrame.TextRange.Font.Size = 20
        Box.TextFrame.TextRange.Font.Bold = msoTrue
        Box.TextFrame.TextRange.Font.ColorIndex = wdRed
        Box.TextFrame.TextRange.InsertSymbol 252, "Wingdings", True
      
        With Selection.Range
        With Box
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .Left =llCoord.Xcoord
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Top = llCoord.Ycoord
        End With
        End With
End Sub

This is not working as the llCoord.Ycoord and llCoord.Xcoord is not relative to the page. I know that 72 points = 1 inc = 2.54 cm. But if you scroll or zoom this does not work anymore.

How do I get the pointer position relative to the page or how do I place the textbox on llCoord.Ycoord and llCoord.Xcoord

Kind Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top