PDA

View Full Version : Solved: Word 2007 Manage Styles



evamads
07-13-2009, 12:53 AM
Hi there,

I have been converting some templates to Word 2007, and I want to write a macro, that will hide certain styles until used, but I don't seem to be able to find the commands? :think:

I can find commands to prevent styles from being shown in the Quick Styles Gallery, but not to hide styles until used.

Does anyone know if this can be done?

Kind regards,
evamads

Paul_Hossler
07-14-2009, 09:48 AM
This is the macro I use

I think you're looking for the .UnhideWhenUsed property of the Style object

It doesn't seem to be documented in help, but does show under Watch

If you have any suggestion/comments about my macro based on your's, I'll be glad to hear



Option Explicit
Sub CleanQuickStyles()
Dim docActive As Document
Dim styleLoop As Style
Dim v As Variant
Dim i As Long


If MsgBox("Do you want to only show the basic and the styles " & _
"currently used in the QuickStyle bar?", _
vbQuestion + vbYesNo, "Marco: CleanQuickStyles") = vbNo Then Exit Sub

Set docActive = ActiveDocument
On Error GoTo PleaseContinue
For Each styleLoop In docActive.Styles

If styleLoop.InUse = True Then
With docActive.Content.Find
.ClearFormatting
.Text = ""
.Style = styleLoop
.Execute Format:=True
If Not .Found Then
'don't know why this seems to work backwards
styleLoop.Visibility = True
styleLoop.QuickStyle = False
Else
styleLoop.QuickStyle = True
'don't know why this seems to work backwards
styleLoop.Visibility = False
styleLoop.UnhideWhenUsed = True
End If
End With
End If
Next styleLoop


'always want to show these in Quickstyle Gallery
v = Array("Heading 1", "Heading 2", "Heading 3", "Heading 4", _
"List", "List Bullet", "Normal", "Table Normal")

For i = LBound(v) To UBound(v)
With ActiveDocument.Styles(v(i))
.QuickStyle = True
'don't know why this seems to work backwards
.Visibility = False
End With
Next i



Exit Sub

PleaseContinue:
Resume Next

End Sub


Paul

evamads
07-15-2009, 06:28 AM
Thank You, Paul

Just what I needed! :bow: