Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
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,521
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
 

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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft