Thread: [Solved] Loop Until End of Document
View Single Post
 
Old 02-15-2023, 12:16 PM
Donfaison Donfaison is offline Windows 10 Office 2016
Novice
 
Join Date: Feb 2023
Posts: 2
Donfaison is on a distinguished road
Default

"Do Until Selection.Range.End = ActiveDocument.Range.End" becomes an infinite loop for me. My code successfully finds wdstyleHeading5 (a title from a journal) and converts the 1st line below it to wdstyleHeading6, the collapses the abstract beneath. This allows me to quickly create an outline and show the first line of the citation (journal & date) when I print. However, once it gets to the end it simply keeps on searching. Any thoughts"
Sub Create_Collapsed_Heading6()
Selection.HomeKey Unit:=wdStory
Do Until Selection.Range.End = ActiveDocument.Range.End
Selection.Find.Style = ActiveDocument.Styles("Heading 5")
Selection.Find.Execute
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Style = wdStyleHeading6
Selection.Paragraphs(1).CollapsedState = True
Loop
ActiveDocument.PrintOut
End Sub
Reply With Quote