Delete styles not in template

C

Chris Mahoney

Hi

I have a template with several styles defined, and I'm trying to write
some code that will remove any styles from the current document that
aren't from the template. Currently I have this:

Dim wrdStyle As Word.Style
Dim templateDoc As Word.Document
Dim templateStyle As Word.Style
Dim StyleFound As Boolean
Set templateDoc =
Documents.Open(FileName:="U:\Settings\templates\styles.xml",
Visible:=False)
For Each wrdStyle In ActiveDocument.Styles
StyleFound = False
For Each templateStyle In templateDoc.Styles
If wrdStyle.NameLocal = templateStyle.NameLocal Then
StyleFound = True
Exit For
End If
Next
If StyleFound = False Then
ActiveDocument.Styles(wrdStyle.NameLocal).Delete
Next
templateDoc.Close

That works, but it's very slow (several seconds). Is there a better way
to accomplish the same thing?

Thanks
Chris
 

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