Temporary styles not deleted

C

Chris Mahoney

Hi

I've written some VBA code which goes through the current document and
removes any styles that aren't defined in a template. It correctly
removes "permanent" styles (ones you define using New Style) but seems
to ignore "temporary" ones (eg. if you select some Normal text and make
it italic, Word will create a new style called Italic). Can anyone tell
me how to check for these "temporary" styles?

Here's the code I'm using:

Dim templateDoc As Word.Document
Dim Styles() As String
Dim CurrentStyle As Integer
Dim wrdStyle As Word.Style
Dim StyleFound As Boolean
Set templateDoc =
Documents.Open(FileName:="U:\Settings\templates\styles.xml",
Visible:=False)
ReDim Styles(templateDoc.Styles.Count)
For CurrentStyle = 0 To templateDoc.Styles.Count - 1
Styles(CurrentStyle) = templateDoc.Styles(CurrentStyle +
1).NameLocal
Next
For Each wrdStyle In ActiveDocument.Styles
StyleFound = False
For CurrentStyle = 0 To templateDoc.Styles.Count
If wrdStyle.NameLocal = Styles(CurrentStyle) Then
StyleFound = True
Exit For
End If
Next
If StyleFound = False Then wrdStyle.Delete
Next
templateDoc.Close

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