P
Peter Rooney
Good morning, all!
Following on from the success of my checkerboard table yesterday (thanks to
all who helped!), I now want to do something that I thought would be simpler,
but in fact has turned out to be more problematical.
I now want to colour alternate columns in the table in one of two different
colours, to produce a striped effect.
However, when I get to the indicated line in the code below, I get "Object
doesn't support this property or method" I'm sure this should be quite easy
to get around - I would have thought that each member of a column would be a
cell, but I'm obviously wrong - can anybody help me out with the correct
syntax, please?
Thanks in advance
Pete
Sub VStripeGrid()
SetRGBColours ' Subroutine to set RGB sequences to colour variable names
GridReset ' Subroutine to sets all cells back to white
FirstForegroundColour = Black
FirstBackgroundColour = Custom1
FirstTexture = wdTextureNone
SecondForegroundColour = Black
SecondBackgroundColour = Custom2
SecondTexture = wdTextureNone
'Set ThisTable = ActiveDocument.Tables(1)
If Not Selection.Information(wdWithInTable) Then
MsgBox ("Select a table before running this macro")
Exit Sub
End If
Set ThisTable = Selection.Tables(1)
ColumnCount = ThisTable.Columns.Count
RowCount = ThisTable.Rows.Count
'MsgBox (RowCount & " rows by " & ColumnCount & " columns")
SetRGBColours
For ColumnCounter = 1 To ColumnCount
If ColumnCounter Mod 2 = 1 Then 'odd numbered column
MsgBox ("Column " & ColumnCounter & " of " & ColumnCount)
----> For Each CellToColour In ThisTable.Columns(ColumnCounter)
With CellToColour.Shading
.ForegroundPatternColor = FirstForegroundColour
.BackgroundPatternColor = FirstBackgroundColour
.Texture = FirstTexture
End With
Next CellToColour
End If
If ColumnCounter Mod 2 = 0 Then 'even numbered column
For Each CellToColour In ThisTable.Columns(ColumnCounter)
With CellToColour.Shading
.ForegroundPatternColor = SecondForegroundColour
.BackgroundPatternColor = SecondBackgroundColour
.Texture = SecondTexture
End With
Next CellToColour
End If
Next ColumnCounter
End Sub
Sub SetRGBColours()
Black = RGB(0, 0, 0)
Blue = RGB(0, 0, 255)
Green = RGB(0, 255, 0)
Cyan = RGB(0, 255, 255)
Red = RGB(255, 0, 0)
Magenta = RGB(255, 0, 255)
Yellow = RGB(255, 255, 0)
White = RGB(255, 255, 255)
Custom1 = RGB(200, 150, 150)
Custom2 = RGB(100, 100, 100)
End Sub
Sub GridReset()
Set ThisTable = ActiveDocument.Tables(1)
ColumnCount = ThisTable.Columns.Count
RowCount = ThisTable.Rows.Count
MsgBox (RowCount & " rows by " & ColumnCount & " columns")
SetRGBColours
For RowCounter = 1 To RowCount
For ColumnCounter = 1 To ColumnCount
Application.StatusBar = "Processing Row: " & RowCounter & ",
Column " & ColumnCounter
'MsgBox ("Row " & RowCounter & ", Column " & ColumnCounter)
CellToColour = ThisTable.Cell(Row:=RowCounter,
Column:=ColumnCounter)
With CellToColour.Shading
.ForegroundPatternColor = Blue
.BackgroundPatternColor = White
.Texture = wdTextureNone
End With
Next ColumnCounter
Next RowCounter
End Sub
Following on from the success of my checkerboard table yesterday (thanks to
all who helped!), I now want to do something that I thought would be simpler,
but in fact has turned out to be more problematical.
I now want to colour alternate columns in the table in one of two different
colours, to produce a striped effect.
However, when I get to the indicated line in the code below, I get "Object
doesn't support this property or method" I'm sure this should be quite easy
to get around - I would have thought that each member of a column would be a
cell, but I'm obviously wrong - can anybody help me out with the correct
syntax, please?
Thanks in advance
Pete
Sub VStripeGrid()
SetRGBColours ' Subroutine to set RGB sequences to colour variable names
GridReset ' Subroutine to sets all cells back to white
FirstForegroundColour = Black
FirstBackgroundColour = Custom1
FirstTexture = wdTextureNone
SecondForegroundColour = Black
SecondBackgroundColour = Custom2
SecondTexture = wdTextureNone
'Set ThisTable = ActiveDocument.Tables(1)
If Not Selection.Information(wdWithInTable) Then
MsgBox ("Select a table before running this macro")
Exit Sub
End If
Set ThisTable = Selection.Tables(1)
ColumnCount = ThisTable.Columns.Count
RowCount = ThisTable.Rows.Count
'MsgBox (RowCount & " rows by " & ColumnCount & " columns")
SetRGBColours
For ColumnCounter = 1 To ColumnCount
If ColumnCounter Mod 2 = 1 Then 'odd numbered column
MsgBox ("Column " & ColumnCounter & " of " & ColumnCount)
----> For Each CellToColour In ThisTable.Columns(ColumnCounter)
With CellToColour.Shading
.ForegroundPatternColor = FirstForegroundColour
.BackgroundPatternColor = FirstBackgroundColour
.Texture = FirstTexture
End With
Next CellToColour
End If
If ColumnCounter Mod 2 = 0 Then 'even numbered column
For Each CellToColour In ThisTable.Columns(ColumnCounter)
With CellToColour.Shading
.ForegroundPatternColor = SecondForegroundColour
.BackgroundPatternColor = SecondBackgroundColour
.Texture = SecondTexture
End With
Next CellToColour
End If
Next ColumnCounter
End Sub
Sub SetRGBColours()
Black = RGB(0, 0, 0)
Blue = RGB(0, 0, 255)
Green = RGB(0, 255, 0)
Cyan = RGB(0, 255, 255)
Red = RGB(255, 0, 0)
Magenta = RGB(255, 0, 255)
Yellow = RGB(255, 255, 0)
White = RGB(255, 255, 255)
Custom1 = RGB(200, 150, 150)
Custom2 = RGB(100, 100, 100)
End Sub
Sub GridReset()
Set ThisTable = ActiveDocument.Tables(1)
ColumnCount = ThisTable.Columns.Count
RowCount = ThisTable.Rows.Count
MsgBox (RowCount & " rows by " & ColumnCount & " columns")
SetRGBColours
For RowCounter = 1 To RowCount
For ColumnCounter = 1 To ColumnCount
Application.StatusBar = "Processing Row: " & RowCounter & ",
Column " & ColumnCounter
'MsgBox ("Row " & RowCounter & ", Column " & ColumnCounter)
CellToColour = ThisTable.Cell(Row:=RowCounter,
Column:=ColumnCounter)
With CellToColour.Shading
.ForegroundPatternColor = Blue
.BackgroundPatternColor = White
.Texture = wdTextureNone
End With
Next ColumnCounter
Next RowCounter
End Sub