Skip table when processing document by paragraph

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Skip table when processing document by paragraph

Post by Robie »

Hi

I am processing/reading a Word document paragraph at a time. It has lots of table in it.
Is there any way I can skip the tables as soon as I read the 1st paragraph in the table (using iPara.Range.Information(wdWithInTable)) and start reading the document after the table?

Thanks.
Robie

User avatar
HansV
Administrator
Posts: 78789
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Skip table when processing document by paragraph

Post by HansV »

Something like this:

Code: Select all

Sub LoopParagraphs()
    Dim par As Paragraph
    Set par = ActiveDocument.Paragraphs(1)
    Do
        ' Process paragraph
        Debug.Print par.Range.Words(1)
        ' Are we there yet?
        If par.Range.End = ActiveDocument.Range.End Then
            Exit Do
        End If
        ' If table, skip the rest
        If par.Range.Information(wdWithInTable) Then
            Do While par.Range.Information(wdWithInTable)
                Set par = par.Next
            Loop
        Else
            Set par = par.Next
        End If
    Loop
End Sub
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Skip table when processing document by paragraph

Post by Robie »

HansV wrote:Something like this:

Code: Select all

Sub LoopParagraphs()
    Dim par As Paragraph
    Set par = ActiveDocument.Paragraphs(1)
    Do
        ' Process paragraph
        Debug.Print par.Range.Words(1)
        ' Are we there yet?
        If par.Range.End = ActiveDocument.Range.End Then
            Exit Do
        End If
        ' If table, skip the rest
        If par.Range.Information(wdWithInTable) Then
            Do While par.Range.Information(wdWithInTable)
                Set par = par.Next
            Loop
        Else
            Set par = par.Next
        End If
    Loop
End Sub
Thank you - that does it. :clapping:

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15716
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Skip table when processing document by paragraph

Post by ChrisGreaves »

Robie wrote:I am processing/reading a Word document paragraph at a time. It has lots of table in it.
Is there any way I can skip the tables as soon as I read the 1st paragraph in the table (using iPara.Range.Information(wdWithInTable)) and start reading the document after the table?
Hi Robie.
I looked at this for a slew of document layout macros I wrote 10+ years ago. If you want, I can dig out the code.

In essence, Iwrote a slew of macros to AutoFormat, AutoFit, Rebuild tables and devised a scheme to allow the user to nominate, by the Selection, whether all tables in the range were to be processed, only those at the start/end of the selection, or all those BUT the ones at the start-end.

In a similar manner I made the same code work for paragraphs, that is, apply an action to all paregraphs in the selection, only the start/end, or all BUT the start/end.
Cheers
Chris
You do not have the required permissions to view the files attached to this post.
By definition, educating the client is the consultant’s first objective