Home > Net >  VBA to create Outline View
VBA to create Outline View

Time:02-01

I use the Web Layout View with collapsible Headings.

How to expand all headings but keep normal Text collapsed ?

this VBA Code processes 1k words in 1second . But on longer documents ( 100k words) it just freezes.

Sub outline_doc2()
    ActiveDocument.ActiveWindow.View.CollapseAllHeadings
    Dim para As Paragraph
    For Each para In ActiveDocument.Paragraphs
        ' if heading is NOT normal Text , expand...
        If para.OutlineLevel <> wdOutlineLevelBodyText Then
            para.CollapsedState = False
            '... but if next paragraph is normal text , then do not expand
            If para.Next.OutlineLevel = wdOutlineLevelBodyText Then
                para.CollapsedState = True
            End If
        End If
    Next
End Sub

CodePudding user response:

These changes are sensitive to the UI, so I'd recommend setting up the ScreenUpdating property while you are doing some work on the Word document:

Application.ScreenUpdating = False
' some work here
Application.ScreenUpdating = True

CodePudding user response:

Currently using a workaround method :

  1. manually indicate Headings to Expand with a " " prefix
  2. Letting an external Script iterate over the Headings and send Expand command it it matches the " " Prefix

On a Document of 50k words , my updated VBA Script still produced no results after 4 minutes so I terminated the process. The External Script had the Document outlined after 1:30 minutes.

App i use for this : strokesplus

  • Related