![]() |
|
#8
|
||||
|
||||
|
Instead of using the 'Heading 4' and 'List Bullet' Styles throughout, had you used a unique Style name for both the 'Ingredients' headings and the ingredients themselves, all you would have to do is to change those Styles' text format to hidden or not-hidden, as desired. You can do that via Styles>Down Arrow>Style Name>Modify>Format>Font. No macros would be needed, though a quite simple macro could be used to do both:
Code:
Sub ShowHideIngredients()
Application.ScreenUpdating = False
With ActiveDocument
With .Styles("Ingredients").Font
.Hidden = Not .Hidden
End With
With .Styles("IngredientItems").Font
.Hidden = Not .Hidden
End With
End With
Application.ScreenUpdating = True
End Sub
As it is, a far simpler macro than you've already been given could be used to toggle the 'Ingredients' display on/off: Code:
Sub ShowHideIngredients()
Application.ScreenUpdating = False
Dim RngHd As Range
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Ingredients"
.Style = wdStyleHeading4
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found
Set RngHd = .Paragraphs(1).Range
Set RngHd = RngHd.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
RngHd.Font.Hidden = Not RngHd.Font.Hidden
.Start = RngHd.End
.Find.Execute
Loop
End With
Set RngHd = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find instances of heading text in the body of my doc, make cross reference to the actual heading
|
MAHE | Word VBA | 4 | 03-03-2018 07:59 AM |
How to delete automatically 500 “Heading 4” and all the contents in this from Navigation?
|
liliaroma | Word VBA | 4 | 11-18-2017 07:53 PM |
| How to Hide/Un-hide a worksheet based on cell on another sheet. | easton11 | Excel Programming | 1 | 06-02-2015 12:07 PM |
Creating a table that automatically updates based on entries of a heading in the document
|
cahphoenix | Word | 3 | 10-29-2014 01:11 PM |
| How to have a heading 1 file automatically appear in each header of any page? | expert4knowledge | Word | 2 | 09-16-2012 10:38 AM |