Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 07-18-2016, 09:14 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,176
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

I believe that the clearformatting is necessary although that doesn't appear to be the case in this instance. Before running the macro, use the regular find/replace dialog to find something formatted a particular way such as Bold or a style perhaps. If you close that dialog and then re-open it, you will see that it remembered this in your previous find. If you then run your macro without clearing those settings the macro has the potential to include those settings in its search. This is why it is good practice to clear this.

However, now that I am testing it, the code seems to ignore those settings which surprises me. In the case of your code, I would have said that you could remove the two lines in the middle
End With
With Selection.Range.Find

since they are not strictly needed but if you do, the strikethrough is ALSO a factor in the second search.

Since you are removing underlining, I would shorten the code and ensure you remove all types of underlining regardless of type. There is no need to search to remove underlining whilst retaining the text
Code:
  With Selection.Range.Find ' Get rid of any stricken-through text
    .ClearFormatting 'Is this needed?
    .Replacement.ClearFormatting 'Is this needed?
    .Text = "*"
    .MatchWildcards = True
    .Font.StrikeThrough = True
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
  End With
  Selection.Range.Font.Underline = wdUnderlineNone    'remove all underlining regardless of type
__________________
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 02:09 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