Hi y’all
I have two small macros set up to format tables the way I like them. One of them (Tableformat) operates on the current table and the other one (Tablesformat) on all the tables in the document.
So far so good.
However, I though, why have two almost identical macros, why not have a private sub that is called by each of them and is passed a table object.
Well, first of all I tried:
Sub Tablesformat() Dim t As Table For Each t In ActiveDocument.Tables doTableformat (t) Next Exit Sub
Calling:
Private Sub doTableformat(t As Table)
But that gave me a type mismatch error? I’d love it if someone could tell me why?
Then I tried swapping and using a Variant.
All seemed to work well with this, untill I reached the line:
With .Borders(wdBorderVertical)
When I got the error “The requested member of the collection does not exist”?
So why does this particular attribute not exist when I call the sub with a table object, when it does exist if I just loop in the code?
More to the point, how do I achieve the end goal of having a sub that I can call with a table object?
Here is the doTableformat Sub:
Private Sub doTableformat(t As Variant) With t With .Rows.First .HeadingFormat = True With .Shading .Texture = wdTextureNone .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = wdColorGray20 End With End With .Rows.AllowBreakAcrossPages = False .Rows.First.Range.ParagraphFormat.KeepWithNext = True With .Borders(wdBorderLeft) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorGray50 End With With .Borders(wdBorderRight) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorGray50 End With With .Borders(wdBorderTop) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorGray50 End With With .Borders(wdBorderBottom) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorGray50 End With With .Borders(wdBorderHorizontal) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorGray50 End With With .Borders(wdBorderVertical) .LineStyle = wdLineStyleSingle .LineWidth = wdLineWidth050pt .Color = wdColorGray50 End With End With End Sub
TIA
Regards
Paul