Find and Replace with Do While and Loops

K

Kim

I have a huge document. Every other sentence is inside a table cell,
for example:

^p
This is sentence one that is inside a table cell^p
Second sentence in table cell^p
^p
....and the pattern repeats from sentence one.

Usually the second sentence starts with the word "Comments:" so what I
would like to do is find the text "Comments:" select that row only,
convert table to text and separate with a space, then find the next
one, or better yet replace all. I can't convert the whole "table"
because I have special formatting that I need to apply to the first
sentence with another macro. Any suggestions on the code?

Thanks,
Kim
 
D

Doug Robbins - Word MVP

Do you want to convert that row (assumed to be row of the table, rather than
a line of text) so that it is not part of the table, which is going to
involve splitting the table before and after that row so that you end up
with a one row table that you convert to text or, would simply removing the
vertical borders from the cells in that row give you what you want?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
K

Kim

Do you want to convert that row (assumed to be row of the table, rather than
a line of text) so that it is not part of the table, which is going to
involve splitting the table before and after that row so that you end up
with a one row table that you convert to text or, would simply removing the
vertical borders from the cells in that row give you what you want?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP









- Show quoted text -

Yes. I want that row to be selected then converted to text, which can
be done without splitting the table. I have created a macro that finds
the word "Comments:", selects that row and converts that row only
without splitting the table. I just want it to loop until it finds all
the occurences of "Comments:"
 
D

Doug Robbins - Word MVP

Use the following:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="Comment", Forward:=True, Wrap:=wdFindStop)
= True
Selection.Rows(1).ConvertToText
Selection.Paragraphs(1).Range.Select
Selection.Collapse wdCollapseEnd
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
K

Kim

Use the following:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="Comment", Forward:=True, Wrap:=wdFindStop)
= True
Selection.Rows(1).ConvertToText
Selection.Paragraphs(1).Range.Select
Selection.Collapse wdCollapseEnd
Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP







- Show quoted text -

Worked perfectly. Thanks much!
 

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