![]() |
#5
|
|||
|
|||
![]()
If you're looking for the character/range position in the document, this might help. If you're looking for the X,Y position on the screen, that's a different problem.
Italophile's solutions may work better, as mine would of course change if you changed the document, moving things around. But this stores the current position of your text as the Range.Start attribute. What exactly are you trying to do with this position once you store it? Just curious as I have never needed to know the position of something in a document. I have needed to know positions when building a UI, or dealing with images, etc. Understanding more of what your bigger goal is may help us help you get there. Code:
Sub position() ' Find characters 1150 and store position in a variable. Dim docRange As Range Set docRange = ActiveDocument.Range Dim str_text As String str_text = "1150" Dim position As Long Dim str_message As String With docRange.Find .ClearFormatting .Text = str_text .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With docRange.Find.Execute ' Store range position = docRange.Start ' Define message for msgBox str_message = (str_text & " is at position: " & position & ".") Call MsgBox(prompt:=str_message, Buttons:=vbOKOnly) End Sub |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Jennifer Murphy | Word | 4 | 02-20-2023 06:36 PM |
Changing Caption Position on Whole Document at once | Alexandarale | Word Tables | 1 | 11-15-2020 06:56 PM |
![]() |
gasparik | Word VBA | 1 | 05-11-2020 05:41 AM |
Starting a document, returning to last position | glennnall | Word | 0 | 10-08-2017 10:09 AM |
![]() |
tinfanide | Excel Programming | 3 | 02-27-2012 03:24 PM |