InUse Property of Styles: What exactly does it mean

B

Bill Bowen

We have been working with a vendor on an issue where a numbering tool
utility of theirs essentially takes a document and analyzes all of the
styles to determine if they are part of an outline numbering scheme.
The problem is that whatever they are using to determine if the style
is part of a scheme iis changing the InUse property of each style in
the document to TRUE. This means that when users work in the document,
all styles in the document become "available styles" or InUse.

So I have a couple of questions. I've tried writing code that will
capture which styles were InUse before their utility is run. This
routine stores each style whose InUse status is set to True into an
array.

<<<<
Public Sub InUseStyles()

Dim n As Integer, x As Integer, y As Integer
Dim TemplateName As String
Dim StylesInUse() As Variant
Dim StyleName As Variant
Dim Styles As Styles

Set Styles = ActiveDocument.Styles
ReDim StylesInUse(0)

For n = 1 To Styles.Count
If Styles(n).InUse = True Then
ReDim Preserve StylesInUse(UBound(StylesInUse) + 1)
StylesInUse(UBound(StylesInUse)) = Styles(n).NameLocal
End If
Next n

End Sub
This procedure works very well in collecting those styles InUse.

But then I want to call their utility (which works fine) and then
reset only those styles that were InUse before I ran their utility.
Here is what I'm doing,

<<<<<
'Now we reset the InUse property back to it's original state
'This first part sets the InUse property of all styles back to false.
Perhaps extraneous...
For x = 1 To ActiveDocument.Styles.Count
ActiveDocument.Styles(x).InUse = False
Next

'This section restores the original InUse styles to True
For y = 1 To UBound(StylesInUse)
Styles(StylesInUse(y)).InUse = True
Next
But I keep getting a "Can't assign to read-only property" of the
section where I set each style to False. I assume it has to do with
not being able to delete Normal or Heading 1, etc... but I'm not sure.
Can anyone tell me if what I am trying to do can be done? I would
prefer if they would just tell us what they are doing to set each
style to InUse but they won't! I just don't think I understand the
InUse property as well as I could. But the vendor doesn't either!

Thanks,

Bill
 
P

Pete Bennett

As with quite a few things in Word, the InUse flag can be fairly ambiguous.

On the most simple level, it just flags any styles that have actually been
used in the document (even if they've been used and the paragraphs affected
have been deleted or restyled to something else).

The property can also be set under some (and I don't know what)
circumstances with outline numbered styles.

Unfortunately, it's not a property that you can reset to False again. My
only suggestion would be to try saving the document as RTF and loading it
back in again, but even that might not work correctly.

If your vendor's software is doing something odd to the documents, then it
really should be working on a copy, and only saving back to the original when
everyone's happy.

The other thing to be very wary about is the number of ListTemplates in the
document. These can be added by Word simply by just looking at the styles
description in the Styles list.

Try it. Create a new document and check the number of ListTemplates

Go into Format/Styles and scroll slowly down the list (so you see the
descriptions update for each one).

Then go back into the VBA editor and check the number of ListTemplates again.

Nasty. You'll have to check if your vendor's software is affecting this as
well, as it could well lead to corrupt numbering in the future.

Enjoy.

Pete.
 

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