Consulting

Results 1 to 3 of 3

Thread: Seeing Heading 1 on opening a Word 2016 document

  1. #1

    Seeing Heading 1 on opening a Word 2016 document

    Sub AutoOpen()
    '
    ' AutoOpen Macro

    ActiveWindow.DocumentMap = True

    'The following code snippet does NOT work, any help would be appreciated

    Selection.Style = ActiveDocument.Styles("Heading 1")

    End Sub

  2. #2
    If you want to select the first instance of the style in a document, if present, then

    Sub AutoOpen()Dim orng As Range
        Set orng = ActiveDocument.Range
        With orng.Find
            .Style = "Heading 1"
            Do While .Execute
                orng.Collapse 1
                orng.Select
                Exit Do
            Loop
        End With
        Set orng = Nothing
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3

    Solution not working for me

    Quote Originally Posted by gmayor View Post
    If you want to select the first instance of the style in a document, if present, then

    Sub AutoOpen()Dim orng As Range
        Set orng = ActiveDocument.Range
        With orng.Find
            .Style = "Heading 1"
            Do While .Execute
                orng.Collapse 1
                orng.Select
                Exit Do
            Loop
        End With
        Set orng = Nothing
    End Sub
    Hopefully, this will clarify my question:

    I want upon opening a document with various Styles in a doc to show in the Navigation Pane, the various Styles 1,2,3, and so on Collapsed
    I have Googled and Bing for a solution previous to my question; but, alas, I cannot find a solution

    Thank you

Posting Permissions

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