Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Find and Replace with Do While and Loops

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kim - 26 Jul 2007 00:22 GMT
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
Doug Robbins - Word MVP - 26 Jul 2007 11:54 GMT
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?

Signature

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

>I have a huge document. Every other sentence is inside a table cell,
> for example:
[quoted text clipped - 14 lines]
> Thanks,
> Kim
Kim - 26 Jul 2007 14:14 GMT
On Jul 26, 5:54 am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> 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
[quoted text clipped - 30 lines]
>
> - 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:"
Doug Robbins - Word MVP - 27 Jul 2007 08:26 GMT
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

Signature

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

> On Jul 26, 5:54 am, "Doug Robbins - Word MVP"
> <d...@REMOVECAPSmvps.org> wrote:
[quoted text clipped - 40 lines]
> without splitting the table. I just want it to loop until it finds all
> the occurences of "Comments:"
Kim - 27 Jul 2007 13:13 GMT
On Jul 27, 2:26 am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Use the following:
>
[quoted text clipped - 67 lines]
>
> - Show quoted text -

Worked perfectly. Thanks much!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.