Log in

View Full Version : [SLEEPER:] Seeing Heading 1 on opening a Word 2016 document



zyzzyva57
06-23-2019, 02:09 PM
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

gmayor
06-23-2019, 08:05 PM
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

zyzzyva57
06-24-2019, 08:54 AM
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