Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2013, 01:53 AM
norgro norgro is offline Highlight only the characters ER when it occurs in SEVERE. Windows XP Highlight only the characters ER when it occurs in SEVERE. Office 2007
Novice
Highlight only the characters ER when it occurs in SEVERE.
 
Join Date: Feb 2013
Location: Perh Australia
Posts: 12
norgro is on a distinguished road
Default Highlight only the characters ER when it occurs in SEVERE.

I am creating a macro to assist with the teaching of Braille for the sighted.



The aim is to highlight in a Word document every occurrence of the characters ER, but only when they occur in the word SEVERE.

I have written code to find occurrences of SEVERE, but I cannot work out how to highlight only the letters ER in every occurrence of the word SEVERE.

If someone can help, I would be very grateful.

The code, as far as I have gone at this stage:
Code:
Sub Highlight_ER_in_SEVERE()
'
'Search for "severe". Highlight only the letters "er".
Set oRng = ActiveDocument.Range
With oRng.Find
  .MatchWholeWord = True
  .Text = "severe"
  .Wrap = wdFindStop 'stops at the end of the document
  While .Execute
    oRng.HighlightColorIndex = wdGreen
  Wend
End With
End Sub

Last edited by macropod; 02-18-2013 at 04:16 AM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 02-18-2013, 04:22 AM
macropod's Avatar
macropod macropod is online now Highlight only the characters ER when it occurs in SEVERE. Windows 7 64bit Highlight only the characters ER when it occurs in SEVERE. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi norgro,

Try:
Code:
Sub Highlight_ER_in_SEVERE()
'Search for "severe". Highlight only the letters "er".
Dim oRng As Range
With ActiveDocument.Range
  With .Find
    .MatchWholeWord = True
    .Text = "severe"
    .Wrap = wdFindStop 'stops at the end of the document
  End With
  While .Find.Execute
    Set oRng = .Duplicate
    With oRng
      .Start = .Start + 3
      .End = .End - 1
      .HighlightColorIndex = wdGreen
    End With
    .Collapse wdCollapseEnd
  Wend
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-18-2013, 01:50 PM
fumei fumei is offline Highlight only the characters ER when it occurs in SEVERE. Windows 7 64bit Highlight only the characters ER when it occurs in SEVERE. Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

or....

Code:
Sub Sev_ER()
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
   Do While .Execute(findtext:="severe", Forward:=True) = True
      With r
         .MoveStart 1, 3
         .MoveEnd 1, -1
         .HighlightColorIndex = wdGreen
         .Collapse 0
      End With
   Loop
End With
End Sub
Reply With Quote
  #4  
Old 02-18-2013, 05:14 PM
norgro norgro is offline Highlight only the characters ER when it occurs in SEVERE. Windows XP Highlight only the characters ER when it occurs in SEVERE. Office 2007
Novice
Highlight only the characters ER when it occurs in SEVERE.
 
Join Date: Feb 2013
Location: Perh Australia
Posts: 12
norgro is on a distinguished road
Default

Thankyou Paul and thankyou Rumei. I am very grateful. I had sprent hours unsuccessfully trying to solve the problem. I really appreciate the time and effort you have put into helping me. Norman
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight only the characters ER when it occurs in SEVERE. count how many tims a certain value occurs lucnijs Excel 6 03-26-2012 09:29 AM
Highlight only the characters ER when it occurs in SEVERE. Highlight the first X number of characters 14spar15 Word 1 11-13-2011 11:17 PM
Highlight Document Jodib PowerPoint 1 10-14-2011 07:25 AM
Junk characters (box-like characters) in Word file Sashikala Word 1 04-20-2010 02:03 PM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft