View Single Post
 
Old 07-19-2022, 04:45 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Yes it can be done but it can be a bit fragile so I use macros to create or destroy the 'numbered body text styles' if they are needed.

Let's say your template already contains the properly defined outline numbers and they are linked to the full set of built-in Heading styles. You can then create the body text partner styles for all of these by creating a style based on that Heading and then changing its attributes to resemble the Normal style.

The code I use to create and remove the styles is this...
Code:
Sub DeleteNormNumStyles()
  Dim sBaseName As String, i As Integer
  sBaseName = "Normal H"
  On Error Resume Next    'avoid error where style doesn't exist
  For i = 1 To 9
    ActiveDocument.Styles(sBaseName & i).BaseStyle = "Normal"   'change base style so paragraphs revert to Normal when style deleted
    ActiveDocument.Styles(sBaseName & i).Delete
  Next i
  On Error GoTo 0   'turn on error checking again
End Sub

'============================================
Sub CreateNormNumStyles()
  Dim sBaseName As String, i As Integer, aStyNormal As Style, aLT As ListTemplate
  
  sBaseName = "Normal H"
  Set aStyNormal = ActiveDocument.Styles(wdStyleNormal)
  Set aLT = ActiveDocument.Styles(wdStyleHeading1).ListTemplate
  Debug.Print "Outline: " & aLT.OutlineNumbered
  
  DeleteNormNumStyles   'removes styles if names already used in this doc
  
  For i = 1 To 9
    ActiveDocument.Styles.Add sBaseName & i, wdStyleTypeParagraph
    With ActiveDocument.Styles(sBaseName & i)
      .BaseStyle = "Heading " & i
      .ParagraphFormat = ActiveDocument.Styles("Heading " & i).ParagraphFormat
      .Font = aStyNormal.Font             'all the same font settings as Normal
      .ParagraphFormat.SpaceAfter = aStyNormal.ParagraphFormat.SpaceAfter
      .ParagraphFormat.SpaceBefore = aStyNormal.ParagraphFormat.SpaceBefore
      .ParagraphFormat.KeepWithNext = False
    End With
  Next i
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote