Amber
02-21-2022, 07:16 AM
I am trying to make a macro that changes the style of all tables in a document. The style it needs to be in has no borders except for the bottom border of the header row.
I've managed to get it to remove all borders, but I can't seem to figure out how to get that one border back in.
This is what I have now:
Sub tablestyle()For Each tbl In ActiveDocument.Tables
'only do this for a table if the first paragraph in the first table cell has the style "Table Heading"
If (tbl.Cell(1, 1).Range.Paragraphs(1).Style.NameLocal = "Table Heading") Then
tbl.Select
'set border lines to no border
Options.DefaultBorderLineWidth = wdLineWidth150pt
Options.DefaultBorderColor = wdColorBlue
With Selection.Borders(wdBorderTop)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderLeft)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderBottom)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderRight)
.LineStyle = noborder
End With
' Set inside lines to no border
Options.DefaultBorderLineWidth = wdLineWidth075pt
Options.DefaultBorderColor = wdColorRed
With Selection.Borders(wdBorderHorizontal)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderVertical)
.LineStyle = noborder
End With
End If
Next
End Sub
Let me add that this is my first time working with VBA, and my understanding of it is not that great yet.
Can anyone give me some pointers on how to make this work?
I've managed to get it to remove all borders, but I can't seem to figure out how to get that one border back in.
This is what I have now:
Sub tablestyle()For Each tbl In ActiveDocument.Tables
'only do this for a table if the first paragraph in the first table cell has the style "Table Heading"
If (tbl.Cell(1, 1).Range.Paragraphs(1).Style.NameLocal = "Table Heading") Then
tbl.Select
'set border lines to no border
Options.DefaultBorderLineWidth = wdLineWidth150pt
Options.DefaultBorderColor = wdColorBlue
With Selection.Borders(wdBorderTop)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderLeft)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderBottom)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderRight)
.LineStyle = noborder
End With
' Set inside lines to no border
Options.DefaultBorderLineWidth = wdLineWidth075pt
Options.DefaultBorderColor = wdColorRed
With Selection.Borders(wdBorderHorizontal)
.LineStyle = noborder
End With
With Selection.Borders(wdBorderVertical)
.LineStyle = noborder
End With
End If
Next
End Sub
Let me add that this is my first time working with VBA, and my understanding of it is not that great yet.
Can anyone give me some pointers on how to make this work?