Lene Fredborg has posted the following reply to a similar question:
****************
Maybe you are looking for something like the following macro. The macro uses
the Visibility property of the styles to first hide all styles and then show
the styles that are included in oArray. In this example, the built-in styles
"Heading 1", "Heading 2" and "Body Text" plus the custom style "MyStyle"
will be shown whereas all other styles will be hidden.
As explained in the comment in the macro, setting the Visibility property to
_true_ means that the style will _not_ be shown (seems rather illogical to
me but that is how it works).
I have found no documentation of Visibility in the VBA help. Originally, I
found the property by recording a macro while changing the check marks in
the Format Settings dialog box that opens when you select Custom from the
Show field in the Styles and Formatting task pane. The styles whose
visibility you set to false will be checked in the Format Settings dialog
box.
Sub ShowHideStyles()
Dim oSty As Style
Dim oArray As Variant
Dim n As Long
'Start deselecting all - NOTE Visibility = true means NOT CHECKED!
With ActiveDocument
For Each oSty In .Styles
.Styles(oSty.NameLocal).Visibility = True
Next oSty
'Display the desired styles - include the names in oArray
oArray = Array(wdStyleHeading1, wdStyleHeading2, wdStyleBodyText, _
"MyStyle")
For n = LBound(oArray) To UBound(oArray)
.Styles(oArray(n)).Visibility = False
Next n
End With
End Sub
****************
--
Stefan Blom
Microsoft Word MVP
in message
news:
[email protected]...