Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2018, 09:59 PM
macropod's Avatar
macropod macropod is offline Formatted list of which heading a specific Style in 'under' Windows 7 64bit Formatted list of which heading a specific Style in 'under' 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

Try:
Code:
Sub CompileInstructions()
Application.ScreenUpdating = False
Dim DocSrc As Document, DocTgt As Document, Rng As Range, r As Long
Set DocSrc = ActiveDocument: Set DocTgt = Documents.Add
With DocTgt
  .Tables.Add .Range, Numrows:=1, NumColumns:=2
End With
With DocSrc.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .Style = "Instructions"
    .Wrap = wdFindStop
    .Execute
  End With
  Do While .Find.Found
    Set Rng = .Paragraphs(1).Range
    With DocTgt.Tables(1)
      .Rows.Add
      r = .Rows.Count
      With .Cell(r, 2).Range
        .FormattedText = Rng.FormattedText
        .Characters.Last.Previous.Delete
      End With
    End With
    Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\HeadingLevel")
    With DocTgt.Tables(1)
      With .Cell(r, 1).Range
        .FormattedText = Rng.Paragraphs.First.Range.FormattedText
        'or, if the output doesn't include all headings from the source
        '.Text = Rng.Paragraphs.First.Range.ListFormat.ListString & vbTab & Rng.Paragraphs.First.Range.Text
        .Characters.Last.Previous.Delete
      End With
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
With DocTgt.Tables(1)
  .Cell(1, 1).Range.Text = "Section"
  .Cell(1, 2).Range.Text = "Instructions"
  .Rows(1).HeadingFormat = True
  .Rows(1).Range.Style = "Strong"
End With
Set Rng = Nothing: Set DocTgt = Nothing: Set DocSrc = Nothing
Application.ScreenUpdating = True
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 04-16-2018 at 02:38 PM. Reason: Code fixes
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatted list of which heading a specific Style in 'under' Creating a list of all text in a specific style ljd108 Word VBA 15 10-09-2014 02:35 AM
Formatted list of which heading a specific Style in 'under' Deleting A blank Line that has a specific heading style , word 2010 & 2013 SteveWcg Word 5 01-08-2014 10:37 PM
Formatted list of which heading a specific Style in 'under' I create a new style but it fails to appear in Quick Style list veronius Word 6 06-18-2013 06:29 PM
Same Style for all Heading Levels nesquik Word 4 05-13-2013 03:31 PM
Formatted list of which heading a specific Style in 'under' Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:12 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