Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-11-2018, 06:29 PM
Guessed's Avatar
Guessed Guessed is offline Loop to Collapse Paragraphs within Range Not Working Windows 10 Loop to Collapse Paragraphs within Range Not Working 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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through all shapes in all stories not working Peterson Word VBA 5 03-04-2018 11:02 AM
Loop to Collapse Paragraphs within Range Not Working Loop through worksheet range to show / hide shapes. wlcdo2 Excel Programming 2 02-22-2017 05:10 PM
Loop to Collapse Paragraphs within Range Not Working Range.Collapse? tinfanide Word VBA 5 01-17-2013 06:02 PM
Loop through folder of workbooks and copy range to other workbook Snvlsfoal Excel Programming 3 07-29-2011 05:55 AM
While loop not working right Cbrehm Excel Programming 0 05-11-2011 11:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft