Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2005
    Location
    Linthicum, Maryland, USA
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    macro for table shading (2003 Prof./SP1)

    Document that will have quite a few tables that have cells coded with letters (VR, NR, R, SR). I'll have to color code each cell. I can do a Find for VR and change cell shading to Blue, and I can repeat that, but very time consuming. I know there has to be a way to do a macro to loop thru tables and change VR to blue, SR to red, etc. Can anyone help? Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: macro for table shading (2003 Prof./SP1)

    Will those cells contain anything else besides the code?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: macro for table shading (2003 Prof./SP1)

    Does this do what you want? You can add as many lines to ColorCodes as you need.

    Sub ColorCodes
    ColorCode "VR", wdColorBlue
    ColorCode "SR", wdColorRed

  4. #4
    Star Lounger
    Join Date
    Jan 2005
    Location
    Linthicum, Maryland, USA
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: macro for table shading (2003 Prof./SP1)

    Oh, it works wonderfully! Thanks so much. If I've never written code (all I can do is record macros), what's the best way to start? Can you give me any pointers? Thanks again.

  5. #5
    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: macro for table shading (2003 Prof./SP1)

    In most cases, recording a macro is a good way to discover what your code needs to do to move around in the document and to change important properties. From there, you often need to add loops, to repeat steps you did manually over and over. There is no "one best way" to write loops; reviewing a lot of examples in the Lounge is a good way to see different tricks. In this case, a "regular" find is run (not a "replace") and then there is a tiny loop that keeps applying the shading for every successful find (it's where the .Execute method is run to "find next").

    I guess the books we remember best are the ones that taught us. I used Woody's "Hacker's Guide to Word for Windows" (for Word 2.0) and a book by Ken Getz (for Word 97), as well as some other titles that weren't as "big picture" but contained useful little solutions. I'm no programmer after 10 years of hacking Word macros, but over time I've learned enough to ask sharp questions here on the boards. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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