View Single Post
 
Old 04-11-2018, 08:10 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
where 'Ingredients' and 'IngredientItems' are the names of the Styles concerned.

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]
Reply With Quote