Hey all, im getting desperate now.
I have a macro running in Word 2003, when I run the macro it *should* put a 'bottom' cell border in each cell that has the style used - this included a border at the top of the table and one at the bottom, like a set of container border for a table with no border within it. i.e
table heading
_______________________________ << top border
text in the table spanning multiple rows and columns
________________________________<< bottom border
So far, the macro will run, only put the border into a cell that has text!, I cant figure out how to make it go in all cells that have the style, regardless of text.
Also, the very last table in the document end up with all table cells getting the border put in, regardless of style.
This is driving me nuts, im not much of a programmer, but this makes me feel stupid. Can someone plz help me.
Thanks alot!
==========Macro code===========
Sub AfterPublish()
AddCellFormatting "Table border"
End Sub
Private Sub AddCellFormatting(StyleName)
' Searches through the document looking for every
' instance of the style "Table Border" and ensures
' that the borders are turned on for the cells
On Error Resume Next
Dim cellInst As Cell
If Not ActiveDocument.Styles(StyleName).InUse Then
' Gets to here if:
' a) the style exists in the document but is not in use.
' b) the style does not exist in the document.
'Err.Clear
Exit Sub
End If
' Set the selection to the beginning of the document.
Selection.StartOf wdStory
With Selection.Find
' Search direction is forward.
.Forward = True
' Clear any other previous search formatting.
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' Search for the style indicating that the cell should have borders.
.Style = ActiveDocument.Styles(StyleName)
' Search for every instance of this style.
Do While .Execute
' Ensure that the selection is in a table.
If Selection.Information(wdWithInTable) Then
'For each cell within the current selection.
For Each cellInst In Selection.Cells
' Apply custom formatting here:
' To turn off any of these lines, remove or
' prefix with a single quote (') character.
' The following line adds a border around the selected cells...
cellInst.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
Next
End If
' Move to the next paragraph
Selection.Move wdParagraph, 1
Loop
End With
End Sub