+ Reply to Thread
Results 1 to 6 of 6

How do I delete rows by shade in WORD

  1. #1
    Registered User
    Join Date
    05-19-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    5

    How do I delete rows by shade in WORD

    Hi all,


    I have a word doc that has many rows and uses multiple different color shades (background fills) to identify the rows. I am trying to create a macro that will select and delete all of the rows which are one color and running into difficulties.

    Any Suggestions?

    Thanks!
    Last edited by Culvernator; 05-27-2011 at 08:38 AM.

  2. #2
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Thumbs up Re: How do I delete rows by shade in WORD

    The following might get you started. This probably needs lots of work to finetune for your specific needs. I use an input box and request for typical color responses: yellow, blue, red, green, pink, gray. I force the response to small case so to remove any case variability. I prompt for these specific colors; add more to InputBox & Case options if you need them. I store the response to a string, then use the Select Case to convert to a number. Then use the .FIND.EXECUTE method to find any highlight. Then, if .FOUND object has .HighlightColorIndex = ColorNum variable, then delete it. Otherwise, if nothing found, then tell user macro is done. If something is found & deleted, then loop back and search again.

    To finetune this for your needs, use the Object Browser (F2) & put cursor on any property or method and hit F1 get the built-in HELP & EXAMPLES to guide you. Hit F7 to get back to code. Hit F8 in VB editor to watch code execute line-by-line; this helps to troubleshoot. Save often and since your deleting stuff, save file as a special test version until you get it right. Good luck.

    Please Login or Register  to view this content.
    Last edited by sauerj; 05-21-2011 at 12:51 AM.

  3. #3
    Registered User
    Join Date
    05-19-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How do I delete rows by shade in WORD

    If you havent guessed this is my first time working with the code and not just recording Macros. I'm a little confused in a couple spots as I want to find any cell in the table that has the wdColorGray35 shading and then to remove the row it is in. I might have butchered the code a little bit:

    Please Login or Register  to view this content.
    Last edited by Culvernator; 05-23-2011 at 12:13 PM.

  4. #4
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Thumbs up Re: How do I delete rows by shade in WORD

    Completely different approach here! The FIND approach won't work as searching for text highlighting will NOT find table cells that are shaded (two completely different things).
    Top part is the same, but bottom part is different; actually pretty simple. Use the 'For Each' loops to go thru all the tables, and then same approach to go thru all the cells in the given table. Check for desired shading in any cell, if found, then delete that cell's row. This assumes you are using the BackgroundPattern color not the ForegroundPattern color. If wrong, then change or add 'OR' statement if you might also be using foregroundpattern color. I added a little counter to report # of deletions. Tweak as necessary.

    Advice on Macros: Understanding "object" language is NOT intuitive. It took me months to start to understand any sort of logical pattern behind the commands. You have to start to really understand the Object Browser (F2 in the VB editor) which is a good guide to help to understand the "pattern". In the Object Browser, right click & click on Group Members; I like this 'view' better. Spend some time and page down thru the objects & commands, and see the various property & method options.
    Lastly, consider buying a VBA Help book. Don't buy one of those HUGE books; its more than you need. Not a lot of good Word VBA books out there; but many good Excel VBA books. You'll learn a lot reading an Excel VBA book (although the commands & options differ from Word VBA at times). I bought Excel Programming by Jinjer Simon, Wiley Publishing, 2nd Edition (LINK). It's pretty good ... or buy any book that is similar to this (i.e. the DUMMY series for example). Good luck!

    Please Login or Register  to view this content.
    Last edited by sauerj; 05-23-2011 at 10:52 PM.

  5. #5
    Registered User
    Join Date
    05-19-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How do I delete rows by shade in WORD

    You are awesome saurej. Theres a few extra things I'd like to see it do but I'm going to try and figure this out on my own. I might be back for more if that fails.

    THANKS

  6. #6
    Forum Contributor sauerj's Avatar
    Join Date
    11-11-2009
    Location
    Lafayette, IN
    MS-Off Ver
    Excel 2019
    Posts
    163

    Re: How do I delete rows by shade in WORD

    Culvernator, Please mark this as SOLVED. That way, no one wastes their time getting into this thread to see if it needs resolved, when it has already been resolved.
    To change status to SOLVED, go back to your 1st note at very top. Click on EDIT. Then click on 'GO ADVANCED'. There's some sort of box where you can toggle the status to SOLVED. Save and it should make this change.
    If you think you might have more questions soon, then wait a little bit before changing status but otherwise best to chg to SOLVED. You can always start another thread and add a HYPERLINK to the previous thread if another question comes up later. ... Regards!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1