#1
|
|||
|
|||
Collapsing headings of same levels but different content
I've got a document that's divided only by level 1 headings to distinguish between different contributors. I'm trying to create a macro that will allow me to collapse all headings except the ones written by the selected contributor.
So far I have this: Code:
Sub OpenJohn() ' ' OpenJohn Macro ' Opens all John Segments ' ' Expand all menus ActiveDocument.ActiveWindow.View.ExpandAllHeadings ' Move cursor to the top Selection.HomeKey Unit:=wdLine, Extend:=wdExtend Selection.HomeKey Unit:=wdStory ' Find first menu using format: Heading 1 Selection.Find.Style = ActiveDocument.Styles("Heading 1") Selection.Find.Execute ' Loop through document collapsing heading if not equal to "John" Do Until Selection.Find.Found = False If Selection.Text Like "John*" Then Selection.Find.Style = ActiveDocument.Styles("Heading 1") Selection.Find.Execute Else: Selection.Paragraphs(1).CollapsedState = True Selection.Find.Style = ActiveDocument.Styles("Heading 1") Selection.Find.Execute End If Loop ' Move cursor to story start Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=3 End Sub |
#2
|
||||
|
||||
Have you considered using bookmarks instead? You should be able to bookmark blocks of a document and then hide/unhide these sections accordingly.
|
#3
|
|||
|
|||
I don't know how bookmarks would work in this case because the individual sections are interspersed throughout the document. For example, the headings might be sequenced:
Bob John Jane John Karen Bob John |
#4
|
||||
|
||||
I'm not certain it would work but if you want to give it a try, just select all the text in a section of your document you wish to hide, then click Insert -> Bookmark and give it an appropriate name (i.e. Bob1 or John1). Then you could write a macro for collapsing/expanding the bookmarked area, something like this:
Code:
Sub ToggleSection(strSection as String) If (ActiveDocument.Bookmarks(strSection).Range.Font.Hidden) Then ActiveDocument.Bookmarks(strSection).Range.Font.Hidden = False Else ActiveDocument.Bookmarks(strSection).Range.Font.Hidden = True End If End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Multiple Userforms Displaying Different Content but Returning Same Content? | marksm33 | Word VBA | 1 | 02-24-2014 06:17 PM |
More than 10 levels in TOC | NobodysPerfect | Word | 4 | 02-07-2014 12:10 AM |
macro for change content of cell2 when content of cell1 changes | Intruder | Excel Programming | 1 | 11-17-2012 08:24 PM |
Help with expanding/collapsing lists of check boxes | Craigap | Word VBA | 3 | 02-05-2012 02:34 PM |
Package for CD with links to Windows media player content and Flash Shockwave content | hectorh | PowerPoint | 4 | 10-15-2009 12:22 PM |