Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-29-2022, 04:54 AM
Bikram Bikram is offline Selection coordinates Windows 10 Selection coordinates Office 2007
Advanced Beginner
Selection coordinates
 
Join Date: Jul 2021
Location: Nepal
Posts: 97
Bikram is on a distinguished road
Default Selection coordinates

Greetings,
Is it possible to get the distance between a selected word and the left margin by VBA word. I searched through a few websites and got hands on some macros which will give the celladress in excel . Could it be modified to get the distance in msword?

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

Set rng = GetRange(llCoord.Xcoord, llCoord.Ycoord)

If Not rng Is Nothing Then
MsgBox "Cell under mouse is :" & rng.Address
Else
MsgBox "Not a valid location."
End If

End Sub

Function GetRange(x As Long, y As Long) As Range
Set GetRange = ActiveWindow.RangeFromPoint(x, y)


End Function
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter x, y coordinates and displays a number arthurz11 Excel 8 05-21-2019 02:26 PM
adding X Y coordinates from 3D Map to source data NOLA Excel 0 04-11-2017 11:10 AM
Parse coordinates in Word stephanberger4 Word 3 08-21-2016 02:05 PM
Selection coordinates addpicture coordinates keep me in the first page Deltaj Word VBA 2 12-04-2014 02:13 PM
Selection coordinates Calculate the coordinates of a DocVariable, Bookmark or paragraph. MaxInCO Word VBA 5 12-11-2013 03:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft