View Single Post
 
Old 10-30-2020, 06:32 AM
Ulodesk Ulodesk is offline Windows 10 Office 2016
Word 2013 Expert Cert
 
Join Date: Sep 2009
Location: Virginia
Posts: 866
Ulodesk is on a distinguished road
Default Macro to strip table styles, please

Some years ago, someone here wrote me a macro to copy just the tables in a Word document and paste then into a new one. The purpose of this is to be able to reformat these tables with a custom table style and apply para styles, as necessary, local formatting, before replacing the tables in the original document with the new ones.

A further step that could be very useful would be replacing the table styles in the new document with the style upon which our custom tables are based, namely, Table Grid. (There are a bunch of MS built-in Table Grid styles, numbered, "light," etc.; I used plain Table Grid, finding it more amenable that Normal.)

I am guessing that this action could be added to the existing macro (see below).

One additional option that would be nice, if possible, would be a separate action to clear text styles. I say option, because, while usually the simplest path is to strip them all and apply the custom paragraph styles, there are times when in long tables, when text and bulleted paragraphs are frequently interspersed, it can be easier to leave bulleted paragraphs bulleted so that finding them is easier. This action might therefore be set off by apostrophe paragraphs and a description line, so that the user could disable that particular part of the macro when desired. (The only way I know to do this is to start each action line with an apostrophe; I'm assuming it would not be many lines long; I'm no coder.)

Would someone be willing to provide this?

Code:
Sub CopyTables()
    Dim Source As Document
    Dim Target As Document
    Dim tbl As Table
    Dim tr As Range

    Set Source = ActiveDocument
    Set Target = Documents.Add

    For Each tbl In Source.Tables
        Set tr = Target.Range
        tr.Collapse wdCollapseEnd
        tr.FormattedText = tbl.Range.FormattedText
        tr.Collapse wdCollapseEnd
        tr.Text = vbCrLf
    Next
End Sub
Reply With Quote