View Single Post
 
Old 03-11-2018, 06:29 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I think you are confused about how the CollapsedState command works. You apply that command to the heading and it will collapse all of the lower level paragraphs under it. So you don't actually need to loop anything if you only want to collapse to the preceding heading.
Code:
Sub CollapseOutlinesWithinHeading()
  'Go to preceding heading and collapse it
  Dim rngHeading As Range
  Set rngHeading = Selection.GoTo(What:=wdGoToHeading, Which:=wdGoToPrevious)
  rngHeading.Paragraphs(1).CollapsedState = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote