I have a very long and complex word document (200+ pages), and would like to extract all content formatted with a certain style, while skipping the rest of the document. It is easy if to do as long as you only need to find one style - but i'm looking for a solution that can extract various styles (ie all headings AND all text formatted as style2).
If you can manage to copy all the test to another document then run this then great, but here's a good start - this is how you can loop through and delete everything that is not of the style you want to keep.
You could do a few if statements instead to check each style, but using a string of all the ok styles and using instr is nice.
Sub DeleteUnwatedFormats()
Dim para As Paragraph
Dim okStyles As String
okStyles = "Normal, Heading1, Heading2" 'list up ok styles
For Each para In ActiveDocument.Paragraphs
If InStr(1, okStyles, para.Style) = 0 Then
para.Range.Delete
End If
Next
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With