Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2015, 08:39 AM
SixStringSW SixStringSW is offline How to highlight lines containing specific words Windows XP How to highlight lines containing specific words Office 2000
Novice
How to highlight lines containing specific words
 
Join Date: Jun 2015
Posts: 2
SixStringSW is on a distinguished road
Default How to highlight lines containing specific words

I have a journal of several years in text format that I'd like to convert to a document, format, and create a print-on-demand book. Individual entries start with lines such as:



Friday, June 12th, 2015

I'd like to write (or preferably, find!) a macro that can search for a pair of strings (e.g, "Monday" && "2015", "Tuesday" && "2015", etc.) and bold that entire line, so it looks like this:

Friday, June 12th, 2015

and maybe in a bigger font.

So in short: either seven macros (for each day of the week) or better, one macro that will look for lines that match words from a pair of lists (("Monday", "Tuesday", "Wednesday", etc.) && ("2000", "2001", "2002", etc.)) and then bold and increase font size.

I'm by no means an expert with RegEx, but I'm a little familiar with the concept. I'm using Word 2000, though I have 2010 if necessary.

Any help? Thanks!
Reply With Quote
  #2  
Old 06-12-2015, 07:05 PM
gmaxey gmaxey is offline How to highlight lines containing specific words Windows 7 32bit How to highlight lines containing specific words Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Someone may be allow with a simplified find and replace, but it is late here:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oPar As Paragraph, oRng As Range
  For Each oPar In ActiveDocument.Range.Paragraphs
    Select Case Trim(oPar.Range.Words.First)
      Case "Sunday", "Monday", "Friday"
        Select Case True
          Case IsNumeric(oPar.Range.Words.Last.Previous)
            Set oRng = oPar.Range.Words.Last.Previous
            oRng.MoveStart wdCharacter, -3
            If IsNumeric(oRng) Then
              oPar.Style = "Body Text" 'Define some style you want to apply.
              
            End If
        End Select
    End Select
  Next oPar
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-12-2015, 10:16 PM
SixStringSW SixStringSW is offline How to highlight lines containing specific words Windows XP How to highlight lines containing specific words Office 2000
Novice
How to highlight lines containing specific words
 
Join Date: Jun 2015
Posts: 2
SixStringSW is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Someone may be allow with a simplified find and replace, but it is late here:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oPar As Paragraph, oRng As Range
  For Each oPar In ActiveDocument.Range.Paragraphs
    Select Case Trim(oPar.Range.Words.First)
      Case "Sunday", "Monday", "Friday"
        Select Case True
          Case IsNumeric(oPar.Range.Words.Last.Previous)
            Set oRng = oPar.Range.Words.Last.Previous
            oRng.MoveStart wdCharacter, -3
            If IsNumeric(oRng) Then
              oPar.Style = "Body Text" 'Define some style you want to apply.
              
            End If
        End Select
    End Select
  Next oPar
lbl_Exit:
  Exit Sub
End Sub
Thanks, I'll give it a try!
Reply With Quote
  #4  
Old 06-03-2018, 07:22 AM
jonjozz jonjozz is offline How to highlight lines containing specific words Windows 10 How to highlight lines containing specific words Office 2016
Novice
 
Join Date: Jun 2018
Posts: 1
jonjozz is on a distinguished road
Default

Sub FindWord_and_ChangeColor()

Dim LastRow, i As Long

Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Text = "put your text here"
.Execute
End With
Do While Selection.Find.Found
Selection.Expand Unit:=wdSentence
Selection.Font.ColorIndex = wdGreen
Selection.Collapse Direction:=wdCollapseEnd
Selection.Find.Execute
Loop
End Sub
Reply With Quote
  #5  
Old 06-03-2018, 03:57 PM
macropod's Avatar
macropod macropod is offline How to highlight lines containing specific words Windows 7 64bit How to highlight lines containing specific words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by gmaxey View Post
Someone may be allow with a simplified find and replace, but it is late here:
You can indeed do it via a wildcard Find/Replace, where:
Find = <[MTWFSondayueshrit]{3,8}, [0-9]{1,2}[nrst][dht] [JFMASONDanuryebchpilgstmov]{3,9}, [12][0-9]{3}>
Replace = ^&
and you apply the appropriate formatting attributes to the replacement expression.

As coded, the above Find expression will find all dates in any of the
• dddd, d(ordinal) mmmm, yyyy
• dddd, d(ordinal) mmm, yyyy
• ddd, d(ordinal) mmmm, yyyy
• ddd, d(ordinal) mmm, yyyy
formats. Its scope could, of course, be made more restrictive.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
formatting, regex



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to highlight lines containing specific words VBA to highlight words if used too much aolszewski Word VBA 3 11-23-2013 02:07 AM
How to highlight lines containing specific words Highlight all underlined words zdodson Word VBA 1 07-11-2013 04:53 PM
How to highlight lines containing specific words Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM
How to highlight lines containing specific words Highlight and then replace multiple words redhin Word VBA 5 03-05-2013 05:42 AM
How to highlight lines containing specific words Find and highlight all words ending in -ly RBLampert Word VBA 13 10-23-2012 04:45 PM

Other Forums: Access Forums

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