Styles, styles... how to hide unused styles?

J

Jörg

I have programmed a vba script that will copy styles, makros, pages, headers,
footers, settings ... from one document to another (update template
collections). After many a nightshift it works, mostly...

One problem could not be solved. The list of the styles visible in the style
selector toolbar of the target document will show ALL styles after I have
copied the styles.

I have been searching the internet for days and found no solution. You are
my last chance...
 
J

Jörg

Tks for the hint. I would need the vba code behind the addin, because I load
a list of templates from a DMS system (several hundred), update styles,
macros, etc. and resave. The addin will not help. Unfortunately the InUse
paramter of styles is readonly.
 
L

Lene Fredborg

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

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
J

Jörg

hi lene

I also used the macro recorder but failed to understand the twisted logic.
Obviously female logic was needed here :eek:)

Thanks a million!!!

Hilsen fra Switzerland
 

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