0
votes

Using the keyboard & mouse I am able to select multiple non-contiguous cells in a table and change properties such as font size & color and cell shading. I can also select multiple columns (contiguous, have not tried non-contiguous). I cannot find a way to do it in VBA and record macro captures nothing.

My objective is simply to shade cell(1,1) through cell(x,y) one color and cells after that another color. I can't get Word ranges to work for me because they apparently go first by row then by column.

I have a 4 column X 20 row table (for printing labels). If the 1st 2 cols and half of col 3 have been printed, I would like to denote that by having those cells in the table one shade and the bottom half (rows 11-20) of column 3 and all of col 4 a different shade. I currently accomplish it by looping through all cells in the table and using row & col indices with If THEN ELSE, but there must be a more efficient way.

I know it would be easier if I would use rows first then columns (and that's what I'm doing now), but it irritates me that I can't do something in VBA that I can do manually.

The real situation is slightly more complex in that there can be 2 different label types on the sheet with different text and different pictures. Any help will be greatly appreciated

1

1 Answers

1
votes

0) don't use rows, use absolute cell ranges

1) if you have 3 sections, you should select them and then recolor them separately

2) the following is a snippet from one of my macros which I use to select only cells 11-17 of all rows past 3 in the 1st table in the document

    ActiveDocument.Range(Start:=ActiveDocument.Tables(1) _
    .Cell(3, 11).Range.Start, End:=ActiveDocument.Tables(1) _  
    .Cell(ActiveDocument.Tables(1).Rows.Count, 17).Range.End).Select

3)the following would set the color to a solid light blue 4)I also recommend wdColorAutomatic to make sure text will be visible on a new background

    Selection.Shading.Texture = wdTextureNone
    Selection.Shading.ForegroundPatternColor = wdColorAutomatic
    Selection.Shading.BackgroundPatternColor = wdColorLightTurquoise

5) remember to select your table properly, if you select the table first you can use

    set aTable as selection.tables(1)

6) to make sure you are in the right table