Delete text based on STYLE?? 
Author Message
 Delete text based on STYLE??

Can't seem to figure out how this could be done...

Is there any way to delete all the text in a Word doc, except the text
tagged w/ a certain style? For example, save only paragraphs not assigned a
Heading 1 style?



Thu, 24 Nov 2005 10:33:41 GMT  
 Delete text based on STYLE??
Hi Tim,
for i = 1 to activedocument.paragraphs.count

next



Thu, 24 Nov 2005 15:53:24 GMT  
 Delete text based on STYLE??
Hi Tim,
try this:
Remove all but Headings

Dim objPrg As Paragraph
For Each objPrg In ActiveDocument.Paragraphs
   If objPrg.OutlineLevel <> 10 Then
      objPrg.Range.Delete
   End If
Next
where outlinelevel represents a word constant
1 ... 9 are headings (wdoutlinelevel1 ... wdoutlinelevel9)
10 is Bodytext (wdOutlineLevelBodyText)

Greetings from Bavaria, Germany
Helmut Weber



Thu, 24 Nov 2005 16:02:29 GMT  
 Delete text based on STYLE??

Thanks, Helmut.

I'll play around w/ this and see if I can get it to do what I need.

I've always stubbornly refused to use Word's default headings, preferring to
use my own system of HD1, HD2, HD3, etc. I also resented the fact that I
couldn't just delete all of Word's built-in styles altogether.

But it appears that my method might result in making some things more
difficult as far as such things as using VBA for calls to document headings
are concerned?


Quote:
> Hi Tim,
> try this:
> Remove all but Headings

> Dim objPrg As Paragraph
> For Each objPrg In ActiveDocument.Paragraphs
>    If objPrg.OutlineLevel <> 10 Then
>       objPrg.Range.Delete
>    End If
> Next
> where outlinelevel represents a word constant
> 1 ... 9 are headings (wdoutlinelevel1 ... wdoutlinelevel9)
> 10 is Bodytext (wdOutlineLevelBodyText)

> Greetings from Bavaria, Germany
> Helmut Weber



Sat, 26 Nov 2005 00:37:37 GMT  
 Delete text based on STYLE??
Hi Tim,
if there is some system in your stylenames,
You might try to exploit that system, e.g.
if left(objprg.style, 2) <> "HD" then
' style is not a heading
or, as I do it,
if left(objprg.style, 2) = "BD" then
' style is bodytext
otherwise, if there is no system, You have
to use a somewhat lengthy "select case" Command.

Greetings from Bavaria, Germany
Helmut Weber



Sat, 26 Nov 2005 13:14:42 GMT  
 Delete text based on STYLE??

Ok, I see what you're saying. Fortunately there is a system wherein all
heading sytles are HD1, HD2, HD3, etc.


Quote:
> Hi Tim,
> if there is some system in your stylenames,
> You might try to exploit that system, e.g.
> if left(objprg.style, 2) <> "HD" then
> ' style is not a heading
> or, as I do it,
> if left(objprg.style, 2) = "BD" then
> ' style is bodytext
> otherwise, if there is no system, You have
> to use a somewhat lengthy "select case" Command.

> Greetings from Bavaria, Germany
> Helmut Weber



Mon, 28 Nov 2005 00:37:52 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Delete range of paragraphs based on start text of paragraphs

2. VB5: Deleting records from a (text) data base?

3. Flat Style text box (with encata style scroll bars)

4. Limiting Styles based on location in the document

5. Insert bookmarks based on style

6. Create & Insert Bookmarks based on style

7. Moving paragraphs based on style

8. Pasting text from the clipboard, finding that text, and applying a style

9. Different text style in same text box

10. Deleted records when text file is linked as table (#deleted)

11. Deleting some of the index fields (in a paragraph style)

12. Deleting unused styles

 

 
Powered by phpBB® Forum Software