Delete range of paragraphs based on start text of paragraphs 
Author Message
 Delete range of paragraphs based on start text of paragraphs

Does anyone know where I can find a code snippet that does
the following?

1) Search the document for first occurrence of "string1"
at the start of a paragraph.

2) Select that paragraph and delete it.

3) Delete all paragraphs from that point THROUGH the next
occurrence of "string2" at the start of a paragraph.

4) Repeat the above until the end of the document is
reached.

I've already tried recording and modifying a macro that
would perform this in the case where the number of down
cursor movements from string1 to string2 is constant.
However, that vertical distance varies from one block to
the next.

Here is an illustration of the text I am working with:

string1RemainingTextInParagraph1A
TextInParagraph2A
string2RemainingTextInParagraph3A

thisIsTheOnlyTextualParagraphThatWillNotBeDeleted

string1RemainingTextInParagraph1B
TextInParagraph2B
TextInParagraph3B
string2RemainingTextInParagraph4B



Wed, 23 Mar 2005 08:55:12 GMT  
 Delete range of paragraphs based on start text of paragraphs
Hi, Jeff,

That approach is so convoluted, it makes my head hurt! :-) Here's something
*much* simpler:

Open the Replace dialog. Click the More button and check the Use Wildcards
option. Put this in the Find What box:

    ^13string1*^13string2*(^13)

and put this in the Replace With box:

    \1

Click Replace All. Done!

If you want a macro so this is easily repeatable, just record the above.

More on wildcard searches here:
http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

Quote:

> Does anyone know where I can find a code snippet that does
> the following?

> 1) Search the document for first occurrence of "string1"
> at the start of a paragraph.

> 2) Select that paragraph and delete it.

> 3) Delete all paragraphs from that point THROUGH the next
> occurrence of "string2" at the start of a paragraph.

> 4) Repeat the above until the end of the document is
> reached.

> I've already tried recording and modifying a macro that
> would perform this in the case where the number of down
> cursor movements from string1 to string2 is constant.
> However, that vertical distance varies from one block to
> the next.

> Here is an illustration of the text I am working with:

> string1RemainingTextInParagraph1A
> TextInParagraph2A
> string2RemainingTextInParagraph3A

> thisIsTheOnlyTextualParagraphThatWillNotBeDeleted

> string1RemainingTextInParagraph1B
> TextInParagraph2B
> TextInParagraph3B
> string2RemainingTextInParagraph4B



Wed, 23 Mar 2005 09:29:52 GMT  
 Delete range of paragraphs based on start text of paragraphs
Jay,

Thanks much. I tried it, and it worked simply and
wonderfully. I'd never considered that approach.

Jeff

Quote:
>-----Original Message-----
>Hi, Jeff,

>That approach is so convoluted, it makes my head hurt! :-
) Here's something
>*much* simpler:

>Open the Replace dialog. Click the More button and check
the Use Wildcards
>option. Put this in the Find What box:

>    ^13string1*^13string2*(^13)

>and put this in the Replace With box:

>    \1

>Click Replace All. Done!

>If you want a macro so this is easily repeatable, just
record the above.

>More on wildcard searches here:
>http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

>--
>Regards,
>Jay Freedman
>Microsoft Word MVP        Word MVP FAQ site:

http://www.mvps.org/word

- Show quoted text -

Quote:


>> Does anyone know where I can find a code snippet that
does
>> the following?

>> 1) Search the document for first occurrence of "string1"
>> at the start of a paragraph.

>> 2) Select that paragraph and delete it.

>> 3) Delete all paragraphs from that point THROUGH the
next
>> occurrence of "string2" at the start of a paragraph.

>> 4) Repeat the above until the end of the document is
>> reached.

>> I've already tried recording and modifying a macro that
>> would perform this in the case where the number of down
>> cursor movements from string1 to string2 is constant.
>> However, that vertical distance varies from one block to
>> the next.

>> Here is an illustration of the text I am working with:

>> string1RemainingTextInParagraph1A
>> TextInParagraph2A
>> string2RemainingTextInParagraph3A

>> thisIsTheOnlyTextualParagraphThatWillNotBeDeleted

>> string1RemainingTextInParagraph1B
>> TextInParagraph2B
>> TextInParagraph3B
>> string2RemainingTextInParagraph4B

>.



Wed, 23 Mar 2005 13:25:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. select paragraph, prompt, select next paragraph

2. Linking a paragraph to another paragraph.

3. Range...Words...paragraphs...HELP

4. How to set a range within a paragraph

5. Setting paragraph (without CR) as Range

6. Return ONLY selected paragraphs within a range that includes a table

7. Paragraph.Range.Footnotes Count/Item Mismatch

8. How to convert word paragraph or range into RTF format

9. Moving paragraphs based on style

10. Blank space at beginning of paragraph when Text Interpretation is set to HTML Text

11. How to set starting paragraph number?

12. Determin which paragraph the selection start is in?

 

 
Powered by phpBB® Forum Software