VBA code or macro to set styles for Headings 1-5 to show in any document? (1 Viewer)

kilroyscarnival

Registered User.
Local time
Today, 10:00
Joined
Mar 6, 2002
Messages
76
I tend to work on other people's documents, and some are made using old templates or editing old reports.

I use Styles a lot, whereas in the past they weren't always used. I've been using headings 1-5 regularly, but in order to get them into the Styles pane, I have to go into Manage Styles and unhide them.

Is there code that would work regardless of which document I was in, that would set Heading 1, 2, 3, 4, and 5 to "Show"? I can adjust the formatting from there as necessary. Alternatively there's no master setting in Word that would instruct it to always display those, is there?

Thanks very much,

Ann
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:00
Joined
Feb 28, 2001
Messages
26,996
There is a thing in VBA called ActiveDocument for which one element is .Styles (a collection). Some of the properties of the .Styles in that collection can be manipulated.


I THINK if you were to write a particular set of code to loop through the collection, you would be able to set the visibility of that style. But I've never tried this so have no clue as to whether I'm sending you down a garden path. The code you want MIGHT (stress MIGHT) look like:

Code:
Dim AStyle as Word.Style
...

For Each AStyle in ActiveDocument.Styles
    If AStyle.Name Like "Heading*" Then
        AStyle.Visibility = True
    End If
Next AStyle
...

This is a GUESS at how you might try it and if I'm totally off-base here, I apologize in advance. This isn't something I do normally so can't swear to it being what you want. But it was the closest thing I could find in my web searches.
 

kilroyscarnival

Registered User.
Local time
Today, 10:00
Joined
Mar 6, 2002
Messages
76
Oops, I thought I had posted a reply at the time! I did try this but it didn't work for me. It's not a huge thing, was just curious. Hopefully I'll eventually get reports all based on newer templates so I won't have to go into Style Manager and alter those. It was fun trying though. Thanks, Doc_Man!
 

Users who are viewing this thread

Top Bottom