Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 07-29-2022, 07:38 AM
macropod's Avatar
macropod macropod is offline Selection coordinates Windows 10 Selection coordinates Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For example:
Code:
With Selection
  MsgBox "HorizontalPositionRelativeToPage: " & .Information(wdHorizontalPositionRelativeToPage) & vbCr & _
  "HorizontalPositionRelativeToTextBoundary: " & .Information(wdHorizontalPositionRelativeToTextBoundary) & vbCr & _
  "VerticalPositionRelativeToTextBoundary: " & .Information(wdVerticalPositionRelativeToPage) & vbCr & _
  "VerticalPositionRelativeToTextBoundary: " & .Information(wdVerticalPositionRelativeToTextBoundary)
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-29-2022, 08:09 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

I am beyond grateful, Macropod. Thank you!!
Reply With Quote
Reply



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 03:58 PM.


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