How to make all table borders invisible in MS Word after copying from HTML

1

I am in a situation where I need to make a HTML report into a word report with nothing more that Ctrl+C or opening it with Word. I end up with a lot of nested tables.

Problem lies in the fact that CSS formats the table in HTML while in Word document they are left with horrible looking borders, that need to be invisible.

It would take extensive amounts of time to make each tables borders invisible.

Is there a way to make all borders of every table in document invisible?

TheBW

Posted 2012-11-06T17:04:49.377

Reputation: 321

Or, maybe, someone knows how to keep CSS formatting. – TheBW – 2012-11-06T17:07:32.070

Answers

4

Create a macro in Word using the following code:

Sub SelectAllTables()
    Dim tbl As Table
    Application.ScreenUpdating = False
    For Each tbl In ActiveDocument.Tables
        tbl.Range.Editors.Add wdEditorEveryone
    Next
    ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
    ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
    Application.ScreenUpdating = True
End Sub

Run the macro to select all tables, then you can modify their borders in one go:

1


Edit: Ok, this should be able to recursively handle nested tables as well to any level:

Sub SelectAllTables()
    Dim tbl As Table
    For Each tbl In ActiveDocument.Tables
        DelTableBorder tbl
    Next
End Sub

Function DelTableBorder(tbl As Table)
    Dim itbl As Table
    tbl.Borders(wdBorderLeft).Visible = False
    tbl.Borders(wdBorderRight).Visible = False
    tbl.Borders(wdBorderTop).Visible = False
    tbl.Borders(wdBorderBottom).Visible = False
    tbl.Borders(wdBorderVertical).Visible = False
    tbl.Borders(wdBorderHorizontal).Visible = False
    tbl.Borders(wdBorderDiagonalUp).Visible = False
    tbl.Borders(wdBorderDiagonalDown).Visible = False
    For Each itbl In tbl.Tables
        DelTableBorder itbl
    Next
End Function

Karan

Posted 2012-11-06T17:04:49.377

Reputation: 51 857

While the macro is working perfectly, It seams that selecting "No borders" option only removes border of main table, not nested tables, which is the biggest issue here. Still, thank you. – TheBW – 2012-11-07T09:17:55.123

@TheBW: Came up with the alternate version above. I'm no VBA expert and it looks ugly, but hopefully it should solve your issue. – Karan – 2012-11-07T16:11:56.283