Consulting

Results 1 to 5 of 5

Thread: First word in paragraph

  1. #1
    VBAX Newbie
    Joined
    Jul 2013
    Posts
    3
    Location

    Unhappy First word in paragraph

    Hi experts.
    I am stuck with a macro that seems to be easy. But i am stuck anyway

    What i need:
    i have a word document.
    I need to check every paragraph in it, and if there first word of paragraph is BAD - then make a background color red, and if the first word is GOOD - then make a background color green.

    i.ve started with classic

    Dim par As Word.Paragraph

    For Each par In ActiveDocument.Paragraphs


    Next


    and then suddently stuck (

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    [VBA]Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oPar As Paragraph
    For Each oPar In ActiveDocument.Range.Paragraphs
    Select Case oPar.Range.Words(1)
    Case Is = "Good": oPar.Range.HighlightColorIndex = wdBrightGreen
    Case Is = "Bad": oPar.Range.HighlightColorIndex = wdDarkRed
    End Select
    Next
    End Sub[/VBA]
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Jul 2013
    Posts
    3
    Location
    Hi Greg, tnanks for such fast reply, unfortunatelly this macro is not working.
    Probably i am not made quite clear description of my problem:

    i have a text in my document:
    BAD Nicholas Angel (Simon Pegg), an extremely dedicated police officer of the London Metropolitan Police Service, performs his duties so well that he is accused of making his colleagues look bad.

    GOOD As a result, his superiors transfer him to "crime-free" Sandford, a town in rural Gloucestershire. Once in Sandford, he immediately arrests a large group of under-age drinkers, and a drunk driver who turns out to be his partner, PC Danny Butterman (Nick Frost), the son of local police inspector Frank Butterman (Jim Broadbent).
    1st paragraph i need to make a red background and 2nd should become green.

    I've run your macro and nothing happens.

    Any advice? and tnahks ahead.
    Last edited by caveman; 07-11-2013 at 12:50 PM.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Try this:

    [VBA]Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oPar As Paragraph
    For Each oPar In ActiveDocument.Range.Paragraphs
    Select Case oPar.Range.Words(1)
    Case Is = "GOOD ": oPar.Range.Shading.BackgroundPatternColor = wdColorBrightGreen
    Case Is = "BAD ": oPar.Range.Shading.BackgroundPatternColor = wdColorDarkRed
    Case Else: oPar.Range.Shading.BackgroundPatternColor = wdColorAutomatic
    End Select
    Next
    End Sub
    [/VBA]
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Newbie
    Joined
    Jul 2013
    Posts
    3
    Location
    Greg - working just perfect. minor problems - but i can fix them bymiself/ Thanks alot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •