J
jferrier15
Hi Everyone, after battling word for about 2 months i need some serious
help. I have been trying to put together a macro that will clean the
unused custom styles. Now after testing lots of code, i found one on
the web that works fairly well:
Dim oStyle As Style
For Each oStyle In ActiveDocument.Styles
If oStyle.BuiltIn = False Then
With ActiveDocument.Content.Find
.ClearFormatting
.Style = oStyle.NameLocal
.Execute FindText:="", Format:=True
If .Found = False Then oStyle.Delete
End With
End If
Next oStyle
Now this code will cause several bugs to happen. The word link style
function causes massive problems and if you delete the linked style,
the original goes as well. I have fixed that problem and I have code
that delinks all the styles in the active document template and makes
the above code run great.
Now my true problem (and I know it occurs from the code above, i have
eliminated every other option) :
On rare occasions (but it has already happened twice with our writers)
when the code above is ran, everything looks great and the styles are
cleaned. Then when you hit save or open the document again, the
document completely collapses. Styles become different names, different
sizes, rename themselves. Some styles turn into others and it's a total
disaster (and it's saved).
Now i have absolutely no idea what to do to fix this occurence. I
cannot debug the code, because this error occurs only once you save and
not during the macro steps. I can't comprehend how this is happening,
because nothing in the code works on anything but the style list.
If anyone out there has seen this before, I will be forever grateful
for any suggestions or ideas.
Except please don't suggest using the .InUse VBasic boolean test. The
..InUse test comes out True for styles that were used once, but then not
used anymore. It's only false for styles that were never used.
help. I have been trying to put together a macro that will clean the
unused custom styles. Now after testing lots of code, i found one on
the web that works fairly well:
Dim oStyle As Style
For Each oStyle In ActiveDocument.Styles
If oStyle.BuiltIn = False Then
With ActiveDocument.Content.Find
.ClearFormatting
.Style = oStyle.NameLocal
.Execute FindText:="", Format:=True
If .Found = False Then oStyle.Delete
End With
End If
Next oStyle
Now this code will cause several bugs to happen. The word link style
function causes massive problems and if you delete the linked style,
the original goes as well. I have fixed that problem and I have code
that delinks all the styles in the active document template and makes
the above code run great.
Now my true problem (and I know it occurs from the code above, i have
eliminated every other option) :
On rare occasions (but it has already happened twice with our writers)
when the code above is ran, everything looks great and the styles are
cleaned. Then when you hit save or open the document again, the
document completely collapses. Styles become different names, different
sizes, rename themselves. Some styles turn into others and it's a total
disaster (and it's saved).
Now i have absolutely no idea what to do to fix this occurence. I
cannot debug the code, because this error occurs only once you save and
not during the macro steps. I can't comprehend how this is happening,
because nothing in the code works on anything but the style list.
If anyone out there has seen this before, I will be forever grateful
for any suggestions or ideas.
Except please don't suggest using the .InUse VBasic boolean test. The
..InUse test comes out True for styles that were used once, but then not
used anymore. It's only false for styles that were never used.