I need help, and I think this is pretty easy if you know VBA:
I want to have a button or dropdown menu that expands/collapses specific menu headings.
Here is an outline of the layout of the document (there are menus and data within the Department levels as well, but I don't need to collapse/expand those levels):
- Daily Processes
- Department A
- Department B
- Department C
- Department D
- Weekly Processes
- Department A
- Department B
- Department C
- Department D
- Monthly Processes
- Department A
- Department B
- Department C
- Department D
- Annual Processes
- Department A
- Department B
- Department C
- Department D
- Appendix
I want there to be buttons for each department, hiding all other departments. For example, if I click Department A, all Dept B, C, D menus will collapse, only showing Dept A.
I would imagine these would be the buttons that I would need:
- ExpandAll
- ShowDeptA
- ShowDeptB
- ShowDeptC
- ShowDeptD
This is the pseudocode for one dept that I think would work:
- ExpandAll
- Start at top of Document
- Search Format=Heading2
- If Heading2=DepartmentA: expand heading, Else: collapse heading
What I have so far: (All I need the command to collapse headings)
Sub OpenDeptA()
'
' OpenDeptA Macro
' Show only DeptA sections
'
' 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 2
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Execute
' Loop through document collapsing heading if not equal to "DeptA"
Do Until Selection.Find.Found = False
If Selection.Text = "DeptA" Then
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Execute
Else: Selection.CollapseHeading ***NOT SURE HOW TO COLLAPSE MENUS***
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Execute
End If
Loop
End Sub
I think this is pretty easy if you know VBA
. Indeed, it isn't so easy... – Kazimierz Jawor