Consulting

Results 1 to 3 of 3

Thread: Solved: Word 2007 Manage Styles

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    29
    Location

    Solved: Word 2007 Manage Styles

    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?

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    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


    [vba]
    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
    [/vba]

    Paul

  3. #3
    VBAX Regular
    Joined
    Jul 2008
    Posts
    29
    Location
    Thank You, Paul

    Just what I needed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •