find text in table and insert page break

T

tbaam

I have a table that extends over multiple pages.
I would like to search for certain text, which is only found in the first
column.
Once this text is found I would like to insert a page break about the row
that the
text is found in. This text would be found in more then one row.

Thank You for you help.
 
H

Helmut Weber

Hi tbaam,

like this:

Sub Test8970()
Dim rTmp As Range
Set rTmp = ActiveDocument.Tables(1).Range
With rTmp.Find
.Text = "test"
.Forward = False ' !!!
While .Execute
If rTmp.Information(wdEndOfRangeColumnNumber) = 1 Then
rTmp.Collapse
rTmp.InsertBreak Type:=wdPageBreak
End If
Wend
End With
End Sub

Without modification that works on the first table in the doc only.
And, note, inserting a pagebreak, splits a table, as far as I know.
Therefore, if "test" is found 7 times,
the number of the tables increases by 7.

The trick is to do it backwards.
If forward would be true, then
after the first find the table would be split,
but no more "test" would be found in the first table.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

hmm...

it is assumed, that "test" is found
at the start of a table cell.

Otherwise, ask again,
can all be done.
 
T

tbaam

Ahh...again PERFECT!

You can't even imagine how close I was....it was the going backwards I
couldn't figure out.
Life is Good!

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top