Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 07-18-2016, 07:25 AM
Robert K S Robert K S is offline Detecting that previous character doesn't exist (i.e., present character is first in document) Windows 7 64bit Detecting that previous character doesn't exist (i.e., present character is first in document) Office 2007
Novice
Detecting that previous character doesn't exist (i.e., present character is first in document)
 
Join Date: Jul 2016
Location: Cleveland, Ohio
Posts: 10
Robert K S is on a distinguished road
Default

Thanks--

Follow-up question: why "declare" the rng variable rather than just always use Selection.Range? (1) It seems like extra code and (2) it actually seems to break the script.

For example, if I do this,

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
With Selection.Range.Find ' Get rid of any underlining
    .Font.Underline = wdUnderlineSingle
    .Replacement.Font.Underline = wdUnderlineNone
    .MatchWildcards = False
    .Text = ""
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
End With
It works as expected, but if I do this:

Code:
Dim rng As Range
Set rng = Selection.Range
With rng.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
With rng.Find ' Get rid of any underlining
    .Font.Underline = wdUnderlineSingle
    .Replacement.Font.Underline = wdUnderlineNone
    .MatchWildcards = False
    .Text = ""
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
End With
It doesn't get rid of the underlining.
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