View Single Post
  #6   Report Post  
Posted to microsoft.public.word.tables
Michael Koerner Michael Koerner is offline
external usenet poster
 
Posts: 41
Default Borders and Shading

Doug; thanks for taking the time. Greatly appreciated. The macro gives me a Run-time error '5': Invalid procedure call,and when I click on debug the following line is highlighted.

If initrng.Characters(1) Init Then
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i + 1))
dtable.Split (newrow)
With newrow

--

Regards
Michael Koerner


"Doug Robbins - Word MVP" wrote in message ...
Try

Sub InsertFramedHeadRow()
' insert a framed header row into the table
Dim i As Long, j As Long
Dim Init As String
Dim newrow As Row
Dim initrng As Range
Dim dtable As Table
Set dtable = Selection.Tables(1)
j = dtable.Rows.Count
Init = dtable.Cell(j, 1).Range.Characters(1)
For i = j To 1 Step -1
Set initrng = dtable.Cell(i, 1).Range
If initrng.Characters(1) Init Then
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i + 1))
dtable.Split (newrow)
With newrow
.Cells.Merge
.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Text = "- " & Init & " -"
.Range.Font.Bold = True
.Range.Shading _
.BackgroundPatternColor = wdColorGray10
.Height = InchesToPoints(0.24)
.Borders.Enable = wdLineStyleSingle
.Borders.OutsideLineWidth = wdLineWidth100pt
End With
Init = initrng.Characters(1)
End If
Next i
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i + 1))
With newrow
.Cells.Merge
.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Text = Init
.Range.Font.Bold = True
.Range.Shading.BackgroundPatternColor = wdColorGray10
End With
End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Michael Koerner" wrote in message ...
Doug;

I thought of that. but my knowledge of macro programming is limited to the spelling of the word macro g Below is the code for the macro that someone provided for me awhile back. If you or anyone can change the code to do this, it would be greatly appreciated. Might be useful to others also.

Sub InsertFramedHeadRow()
' insert a framed header row into the table
Dim i As Long, j As Long
Dim Init As String
Dim newrow As Row
Dim initrng As Range
Dim dtable As Table
Set dtable = Selection.Tables(1)
j = dtable.Rows.Count
Init = dtable.Cell(j, 1).Range.Characters(1)
For i = j To 1 Step -1
Set initrng = dtable.Cell(i, 1).Range
If initrng.Characters(1) Init Then
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i + 1))
With newrow
.Cells.Merge
.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Text = "- " & Init & " -"
.Range.Font.Bold = True
.Range.Shading _
.BackgroundPatternColor = wdColorGray10
.Height = InchesToPoints(0.24)
.Borders.Enable = wdLineStyleSingle
.Borders.OutsideLineWidth = wdLineWidth100pt
End With
Init = initrng.Characters(1)
End If
Next i
Set newrow = dtable.Rows.Add(BeforeRow:=dtable.Rows(i + 1))
With newrow
.Cells.Merge
.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Text = Init
.Range.Font.Bold = True
.Range.Shading.BackgroundPatternColor = wdColorGray10
End With
End Sub



--

Regards
Michael Koerner


"Doug Robbins - Word MVP" wrote in message ...
It might be better to modify the macro so that it splits the table before the row that is added so that the application of the border to that row will have no impact on the previous row.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Michael Koerner" wrote in message ...
I do a mail merge from Excel into a Word table. Once the merge is completed, I have a macro (thanks to someone in this NG) which goes through the table, and when the first letter of the last name (column 1) changes it inserts a new row, combines all the cells sets the shading to 10%grey, centers an upper case character for that letter and inserts a border around that cell. The problem arises when the newly created cell is the first row on a new page, the last row on the previous page contains a bottom border which should not be there.

If I select the last row on the page, and delete the border, the border is removed from the top of the next page also. The only way I have found to keep the border where it is required and remove it from where it is not wanted is to delete the border one cell at a time rather than selecting the whole row at once. I was wondering if there might be an easier way to do this?

--

Regards
Michael Koerner