Solved

Round Corners of a table

Posted on 2006-12-01
7
3,234 Views
Last Modified: 2012-05-05
Hi experts,

I want to format a table with rounded corners - is there any way of doing this?

Cheers,
Norb.
0
Comment
Question by:Norbert2000
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Dreamboat
Comment Utility
No.
Sorry.
Use graphics.
0
 
LVL 1

Author Comment

by:Norbert2000
Comment Utility
I assume you would make a graphical box (with rounded corners) and placed the table over it?  Can you do that with a table that grows and shrinks via automation?
0
 
LVL 22

Expert Comment

by:Dreamboat
Comment Utility
Do you want the entire table to have rounded corners? Or the individual cells?
If the individual cells, you could use a graphic, create a row, then make an autotext entry from it.

I'm assuming that since no coders have chimed in, this could be painful using VBA (or at least painful to consider doing it for free?).
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
The procedure below will replace the outer table borders with a rounded rectangle. It would be somewhere between extremely difficult and impossible to make the border adjust dynamically, does it for the table passed into it.

You can test it on the first table in the active document like this:

Sub CallRC()
 RoundCorners activedocument.tables(1)
end sub

I don't know if it is rigorous enough, but it works in simple tests.

Sub RoundCorners(tbl As Table)
    Dim sh As Shape
    Dim c As Integer
    Dim r As Integer
    Dim col As Column
    Dim rw As Row
    Dim cl As Cell
    Dim tblH As Single
    Dim tblW As Single
    Dim doc As Document
    'delete any existing autoshape(s)
    On Error GoTo RoundCornersError
    tbl.Range.ShapeRange.Delete
    For r = 1 To tbl.Rows.Count
        For c = 1 To tbl.Columns.Count
            Set cl = tbl.Cell(r, c)
            If r = 1 Then
                cl.Borders(wdBorderTop).LineStyle = wdLineStyleNone
            Else
                cl.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
            End If
            If c = 1 Then
                cl.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            Else
                cl.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            End If
            If r = tbl.Rows.Count Then
                cl.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            End If
            If c = tbl.Rows.Count Then
                cl.Borders(wdBorderRight).LineStyle = wdLineStyleNone
            End If
        Next c
    Next r
    For Each col In tbl.Columns
        tblW = tblW + col.Width
    Next col
    For Each rw In tbl.Rows
        rw.HeightRule = wdRowHeightExactly
        tblH = tblH + rw.Height
    Next rw
    Set doc = tbl.Parent
    Set sh = doc.Shapes.AddShape(msoShapeRoundedRectangle, 0, 0, tblW, tblH, tbl.Range)
    sh.Fill.Transparency = 1
    sh.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    sh.Left = tbl.Range.Information(wdHorizontalPositionRelativeToPage) - doc.PageSetup.LeftMargin
RoundCornersExit:
Exit Sub
RoundCornersError:
    Select Case Err.Number
    Case 5852 'Object not available (no shapes anchored to table range)
        Resume Next
    Case Else
        MsgBox "Unexpected error - " & Err.Description
        Resume RoundCornersExit
    End Select
 
End Sub



0
 
LVL 1

Author Comment

by:Norbert2000
Comment Utility
I am really sorry I didn't except this solution sooner - it does exactly what I want.

Thank you very much.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now