View Single Post
 
Old 01-13-2024, 05:55 AM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi, again! If you don't mind here are some comments to your previous post.
1) If the cursor (aka selection or insertion point) is within a word (in our case a digit) that wd is considered selected. 'Within', besides within proper, also inlcudes the positions immediately before and after the word, What is more: 'within' also includes the word's trailing space! In other words, if the cursor is placed immediately before or on, or immediately after the word, or immediately after the word's trailing space, the word is treated as selected. That's why your digit becomes replaced. A rule of a thumb I use: if I want to make sure what the word is, I just double-click on it (use this technique to get surprised). If the word is followed by space, that space is also selected. Other punctuation signs do not belong to the previous word, they are individual words.
2) If you have error 5941 ("Requested Member of the Collection Does Not Exist"), most likely there's a paragraph break/empty paragraph in the selected range, which 'confuses' the code. In this case, I'd suggest adding another condition
Code:
If Len(oPar.range) > 1 Then
right after
Code:
For Each oPar In oRng.Paragraphs
and, of course, adding
Code:
End If
before
Code:
Next oPar
3) I prefer using Selection to ActiveDocument, that's why I used Selection in the code, although you intended to work on the whole document. My reason is simple: ActiveDocument may be too much of a good thing when there's no need to change the whole document. At the same time, selection can be extended to the whole document, if need be, by pressing Ctrl+A with your left hand. As you see, for me Selection is more practical. It's only my opinion.

I hope the above tips/explanations will help and even "system-specific variations" of the code execution will disappear.
Reply With Quote