Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 07-18-2016, 04:58 PM
Guessed's Avatar
Guessed Guessed is offline Detecting that previous character doesn't exist (i.e., present character is first in document) Windows 10 Detecting that previous character doesn't exist (i.e., present character is first in document) Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It was declared because that same range was needed 5 times and the code was completely different to your second question. Declaring a range makes it easier to follow the code and can reduce the number of contextual jumps required by the code. For instance
Selection.Range requires Word to first find out which document is active, then determine the start and finish positions of the selection in that document and then remember that range for the next command. Using a declared range reduces the 'thinking' required by the code.
Working with ranges also reduces the ambiguity of where the 'selection' is located at any time. If your code happens to change the selection: either in the activedocument or because you have opened/activated a different document, the Selection.Range will give a very different result and is probably not what you were expecting.

Now it just so happens that rng.Find is somewhat buggy and when something is found, the rng collapses to the found text. That is why your code doesn't 'find' anything underlined. In that case, you would need to redefine the range before doing the second find.

In answer to your question in the code - I would think that the second find is actually searching for underlined AND strikethrough text since you didn't clear the formatting after the first time. That is the point of the .clearformatting which removes any of the sticky formatting that might already be retained from a previous finds performed by the user prior to your code running. You would need to .clearformatting again to remove the strikethrough condition in the second find before applying the font.underline condition otherwise you are searching for text with both.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting that previous character doesn't exist (i.e., present character is first in document) Macro to list all character styles in a document ljd108 Word VBA 11 08-28-2024 01:20 AM
Detecting that previous character doesn't exist (i.e., present character is first in document) Replace a random character with the same character RickLegrand Word 7 07-23-2015 06:35 PM
Detecting that previous character doesn't exist (i.e., present character is first in document) How can select from a specific character to another character mohsen.amiri Word 2 02-19-2015 11:38 PM
Detecting that previous character doesn't exist (i.e., present character is first in document) Regular (roman) character style doesn't change text to roman kcbenson Word 2 10-16-2014 01:31 PM
Detecting that previous character doesn't exist (i.e., present character is first in document) Finding or searching ^ character in word document shahin3121 Word 2 03-05-2012 06:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:15 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