Manage Styles using VBA?

  • Thread starter Thread starter xtine
  • Start date Start date
X

xtine

Can you programmatically control the styles that are shown in the
Style Gallery and in the styles list (where they are previewed)?

Can you write macros to permit/hide etc. the built-in styles?


Christine
 
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]...
 
Thanks

this looks like what I was looking for... will try it out soon


Christine
 

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

Back
Top