Results 1 to 11 of 11
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I get a heading style name (Word 2002 /XP SP3)

    Im writing code to obtain all the heading styles in the document. Im wanting to search for a heading style name.
    However it appears there is no property for a style name. is this correct? of is it getting late in the afternoon [img]/forums/images/smilies/ohmy.gif[/img])

    diana

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    I suspect NameLocal is the property you're looking for.

  4. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    The Style property is the name: HTH --Sam
    <pre>Option Explicit
    '
    Sub CollectHeadingStyles()
    Dim p As Paragraph
    Dim c As Collection
    Set c = New Collection
    For Each p In ActiveDocument.Paragraphs
    If Left(p.Style, 7) = "Heading" Then
    On Error Resume Next ' Ignore dups
    c.Add Item:=p.Style, Key:=p.Style
    On Error GoTo 0
    End If
    Next p
    Dim msg As String, i As Integer
    For i = 1 To c.Count
    msg = msg & c(i) & vbCr
    Next i
    MsgBox msg
    End Sub
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    ... and if you want to tell apart heading styles from the rest, look at myStyle.ParagraphFormat.OutlineLevel

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  6. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    Ahhh, you can tell that I usually only do Excel Macros. I'll correct my code and post it for Diana. Thanks!
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  7. #6
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    With help from Klaus, here's a better solution:
    <pre>Option Explicit
    '
    Sub CollectHeadingStyles()
    Dim p As Paragraph
    Dim c As Collection
    Set c = New Collection
    For Each p In ActiveDocument.Paragraphs
    If ActiveDocument.Styles(p.Style).ParagraphFormat.Out lineLevel _
    <> wdOutlineLevelBodyText Then
    On Error Resume Next ' Ignore dups
    c.Add Item:=p.Style, Key:=p.Style
    On Error GoTo 0
    End If
    Next p
    Dim msg As String, i As Integer
    For i = 1 To c.Count
    msg = msg & c(i) & vbCr
    Next i
    MsgBox msg
    End Sub
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  8. #7
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    BTW, I was assuming that you only wanted used styles. It's much easier to get all the heading styles & it shows the use of NameLocal mentioned earlier:
    <pre>Sub AllStyle()
    Dim msg As String, s As Style
    For Each s In ActiveDocument.Styles
    If s.Type = wdStyleTypeParagraph Then
    If s.ParagraphFormat.OutlineLevel <> wdOutlineLevelBodyText Then _
    msg = msg & s.NameLocal & vbCr
    End If
    Next s
    MsgBox msg
    End Sub
    </pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  9. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    Many thanks Sam, Klause and Steeeve

    diana <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  10. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    ...i have the following code.

    it locates the style OK.
    yesterday the code was working. in that it locates the style and changes the Font colour to white, which is reflected in the text in the documnet.
    Todays a different day and doesnt change the Font colour in the document. Although the style reads as Font:White.

    Is there something wrong with my code?
    t was working in the sense that it would

    Dim styDesc As Style
    Dim blnStyleExists As Boolean

    blnStyleExists = False

    '
    'check all styles in the document
    '
    For Each styDesc In ActiveDocument.Styles

    '
    ' is the style the IDD heading style
    '
    'MsgBox styDesc.NameLocal
    If InStr(1, styDesc.NameLocal, "Style IDDVariableMarker") > 0 Then
    blnStyleExists = True

    '
    ' check the Font colour set for the heading style
    ' if the Font colour is "Automatic"
    '
    'MsgBox styDesc.Description
    If InStr(1, styDesc.Description, "Font color: Auto") > 0 Then

    '
    ' change the Font colour to "White"
    '
    With ActiveDocument.Styles(styDesc.NameLocal).Font
    .Color = wdColorWhite
    End With

    blnStyleExists = True
    Exit For

    ElseIf InStr(1, styDesc.Description, "Font color: White") > 0 Then

    Exit For
    End If
    End If

    Next styDesc



    many thanks diana

  11. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    What happens if you select some of the text that should have white font but hasn't, then press Ctrl+Spacebar? If the font becomes white after all, direct formatting had been applied to the text.

  12. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How do I get a heading style name (Word 2002 /XP SP3)

    Many thanks Hans

    I'll give that ago!
    diana <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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