Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Find text with coloured background (Any)

    For the record.

    I wanted my macro to test whether a document contains any text with a coloured background. I tried "ActiveDocument.Content.Font.Shading.BackgroundPat ternColorIndex", but it returned 9999999 even if the document did NOT contain any text with a coloured background.

    So, I ldid the same test, but looping through the paragraphs, and that seems to work.

    Dale

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find text with coloured background (Any)

    Hi Dale
    I'd be interested in seeing the snippet of code that you ended up with.

    T.I.A.
    Regards
    Don

  4. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find text with coloured background (Any)

    I think Word will always return wdUndefined (9999999) for any kind of formatting if the range/selection has more than 40 paragraphs, or thereabouts.

    <img src=/S/frown.gif border=0 alt=frown width=15 height=15> Klaus

  5. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Find text with coloured background (Any)

    Ah. That explains my variable results.

    Thanks, Klaus
    Dale

  6. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Find text with coloured background (Any)

    Hi Don

    Here's the snippet:<pre>For Each MyParagraph In ActiveDocument.Paragraphs
    If MyParagraph.Range.Font.Shading.BackgroundPatternCo lorIndex <> wdAuto Then
    MyMessage$ = "The document contains text with a coloured background."
    MyParagraph.Range.Select
    GoTo ErrorProcessing
    End If
    Next MyParagraph</pre>


  7. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find text with coloured background (Any)

    Thanks Dale
    Regards
    Don

  8. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Find text with coloured background (Any)

    This sounds very familiar. I know that if you select more than 50 paragraphs, the Style, Font, and Font Size boxes on the Formatting toolbar blank out (even if the values in the 51st paragraph remain the same), at least in Word 2002 and earlier.

    Given the increased horsepower of today's computers, I hope this limitation can be removed sooner rather than later. Particularly from VBA. Perhaps there is a range-oriented solution that works around this problem, but I haven't read back up the thread to see how it might be implemented to test that possibility.

Posting Permissions

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