View Single Post
 
Old 08-16-2013, 03:40 AM
lsmcal1984 lsmcal1984 is offline Windows XP Office 2003
Novice
 
Join Date: Aug 2013
Posts: 18
lsmcal1984 is on a distinguished road
Default Combining two pieces of VBA to create caption field above table

Dear all,

I have inherited two macros that are used to generate a caption field at the top of a table in each document. It does this by inserting a row above the current row, however there is a caveat (explained after the code):

Code:
 
Sub InsCptnRw()
Selection.InsertRowsAbove 1
Selection.Cells.Merge
With Selection.Cells
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorAutomatic
End With
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = 7810048
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
End Sub
And:

Code:
 
Sub HdrRw()
With Selection.Cells
With .Shading
.Texture = wdTextureNone
.BackgroundPatternColor = RGB(40, 70, 111)
End With
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = 7810048
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = 7810048
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = 7810048
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
'.LineWidth = wdLineWidth05pt
.Color = RGB(255, 255, 255)
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
End Sub
When this code is used, a row is created with text in caption style. However, the row below it appears in white (as the previous top row in the table is white). It would be great to create code that inserts this top row as caption style text in black and the row below converts to white text.

This is much appreciated and I hope it's clear.
Reply With Quote