Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2016, 09:48 PM
gmayor's Avatar
gmayor gmayor 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 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Come to that you could simply use


Code:
    With Selection.Font
        .Underline = wdUnderlineNone
        .StrikeThrough = False
    End With
which will remove underlining and strikethough from the selected text. Or for the main story range
Code:
    With ActiveDocument.Range.Font
        .Underline = wdUnderlineNone
        .StrikeThrough = False
    End With
If you want to use .Find then note that this does not limit the search to the end of the selected text, so test for the range being in the selection e.g.
Code:
Dim oRng As Range
    Set oRng = Selection.Range
    With oRng.Find
        .Font.StrikeThrough = True
        Do While .Execute
            If oRng.InRange(Selection.Range) Then
                oRng.Font.StrikeThrough = False
                oRng.Collapse 0
            End If
        Loop
    End With
    Set oRng = Selection.Range 'Reset the range
    With oRng.Find
        .Font.Underline = wdUnderlineSingle
        Do While .Execute
            If oRng.InRange(Selection.Range) Then
                oRng.Font.Underline = wdUnderlineNone
                oRng.Collapse 0
            End If
        Loop
    End With
Or for the whole main story range the test is not required e.g.
Code:
Dim oRng As Range
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .Font.StrikeThrough = True
        Do While .Execute
            oRng.Font.StrikeThrough = False
            oRng.Collapse 0
        Loop
    End With
    Set oRng = ActiveDocument.Range 'Reset the range
    With oRng.Find
        .Font.Underline = wdUnderlineSingle
        Do While .Execute
            oRng.Font.Underline = wdUnderlineNone
            oRng.Collapse 0
        Loop
    End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



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