View Single Post
 
Old 10-17-2020, 03:04 PM
John 4 John 4 is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Oct 2019
Posts: 69
John 4 is on a distinguished road
Default

Many thanks Graham for your speedy response.

Here's your code, with some lines stripped out that appeared unnecessary (unless you can say otherwise?), inserted into the loop:
Code:
Dim oTable As Table
Dim oRng As Range
For Each oTable In ActiveDocument.Tables
    oTable.Select
        Set oTable = Selection.Tables(1)
        Set oRng = oTable.Range
        oRng.Collapse 1
        oRng.Select
        Selection.SplitTable
        Set oRng = oTable.Range
        oRng.Collapse 0
        oRng.InsertParagraphAfter
Next
End Sub
It works perfectly except for when tables are butted; in which case it adds a row to the top of the bottom butting table instead of separating them (I don't know why, because if i place the cursor in the same place (the collapse position) and select "split table" manually it works, i.e. separates the tables with a paragraph).

It was doing something very strange for a while if I traced through it with the F8 key instead of "running" it: when it came to the butting tables it would copy the first page of the document and paste it onto the end of the document while deleting the original last page. (Both problems were occurring before [and after I think] I stripped the extra lines out of the code by the way).

I'm not sure what settings I've changed, but the tables are no longer pasting as butted together so the mentioned strange problem has taken care of itself apparently; as well as the problem with adding a row instead of separating the tables. So everything's working well now

Many thanks for your help. Seeing what way people code who actually know how to code is very informative.

And thanks also to Macropod, the space at the top of the page doesn't bother me now like I said, but it may become an issue in future. And of course his "Update All Documents in a Folder" macro is gold
Reply With Quote