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
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