Convert outline to a multilevel list

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Convert outline to a multilevel list

Post by gailb »

I have a Word document downloaded from the Web. This document contains almost 70 different outlines, but none of them are connected. If I look at the styles, the entire document is in Normal, but if I right click on the outline, I can choose to adjust.

How can I get set the whole document so it use the same multilevel throughout, that way I can adjust indent and such all at once.

User avatar
HansV
Administrator
Posts: 78234
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Convert outline to a multilevel list

Post by HansV »

I 'd assign heading styles to the outline paragraphs.
Best wishes,
Hans

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Not entirely following. I know how to create the styles, but wouldn't you have to apply the styles to each level of the outline?

User avatar
HansV
Administrator
Posts: 78234
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Convert outline to a multilevel list

Post by HansV »

Yes, Heading 1 for level 1, Heading 2 for level 2 etc.
Best wishes,
Hans

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Thanks, I'll give it a go

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Convert outline to a multilevel list

Post by macropod »

What numbering format is used for the various levels (e.g. 1, 1.1, 1.1.1, etc)?
Paul Edstein
[Fmr MS MVP - Word]

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Hi Paul,

It starts with roman numeral I

It's I, A, 1, a, i

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Convert outline to a multilevel list

Post by Charles Kenyon »

Paul may come up with a macro for you. In the meantime, see Shauna Kelly's How to Create Outlines or Numbered Headings

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Convert outline to a multilevel list

Post by macropod »

Try the following two macros.

The first macro applies your numbering scheme to the first 5 heading levels. You'll see a line with '.TextPosition = CentimetersToPoints(0.5 + i * 0.5)'. This indents each heading level by 0.5cm. You could use InchesToPoints instead to use those, and you could change the 0.5 to something else.

The second macro goes through your document looking for paragraphs whose first word conforms to one of those levels and applies that level to the paragraph. It is assumed that each level's numbering restarts once content at the previous level is encountered.

Code: Select all

Sub ApplyMultiLevelHeadingNumbers()
Dim LT As ListTemplate, i As Long
Set LT = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
For i = 1 To 5
  With LT.ListLevels(i)
    .NumberFormat = Choose(i, "%1", "%2", "%3", "%4", "%5")
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = Choose(i, wdListNumberStyleUppercaseRoman, wdListNumberStyleUppercaseLetter, _
      wdListNumberStyleArabic, wdListNumberStyleLowercaseLetter, wdListNumberStyleLowercaseRoman)
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = CentimetersToPoints(0.5 + i * 0.5)
    .ResetOnHigher = True
    .StartAt = 1
    .LinkedStyle = "Heading " & i
  End With
Next
End Sub

Code: Select all

Sub ApplyHeadingStyles()
Dim Para As Paragraph, Rng As Range, i As Long, StrTxt As String, bLvl As Boolean
Dim objUndo As UndoRecord: Set objUndo = Application.UndoRecord
With ActiveDocument.Range
  For Each Para In .Paragraphs
    With Para
    StrTxt = Trim(.Range.Words.First.Text): bLvl = False
    objUndo.StartCustomRecord ("Fmt")
      For i = 1 To 5
        .Style = "Heading " & i
        If .Range.ListFormat.ListString = StrTxt Then
          .Range.Words.First.Text = vbNullString
          bLvl = True: Exit For
        End If
      Next
      objUndo.EndCustomRecord
      If bLvl = False Then ActiveDocument.Undo
    End With
  Next
End With
End Sub
Last edited by macropod on 12 Jul 2022, 08:41, edited 1 time in total.
Paul Edstein
[Fmr MS MVP - Word]

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Hi Paul,

Evidently I am not understanding how this works, plus, the second macro debugs on

Code: Select all

If bLvl = False Then Undo
Sub or Function not defined

The first macro ran, but not all that sure what it did.

Here is a pared-down version of the doc. As you can see, everything is in Normal style, but the outlines are in order. I just would like to control the outline with the styles so I can adjust the spacing, fonts, indents, etc.
Outline.docx
You do not have the required permissions to view the files attached to this post.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Convert outline to a multilevel list

Post by macropod »

Your list-level numbering is not as described. Rather than being 'I, A, 1, a, i', it is 'I., A., 1., a., i.'. Plus your Heading Styles use a range of formats that I suspect you don't really want. All of that can be addressed by:

Code: Select all

Sub ApplyMultiLevelHeadingNumbers()
Dim LT As ListTemplate, i As Long
Set LT = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
For i = 1 To 5
  With LT.ListLevels(i)
    .NumberFormat = Choose(i, "%1.", "%2.", "%3.", "%4.", "%5.")
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = Choose(i, wdListNumberStyleUppercaseRoman, wdListNumberStyleUppercaseLetter, _
      wdListNumberStyleArabic, wdListNumberStyleLowercaseLetter, wdListNumberStyleLowercaseRoman)
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = CentimetersToPoints(1.25 + i * 1.25)
    .ResetOnHigher = True
    .StartAt = 1
    .LinkedStyle = "Heading " & i
  End With
  With ActiveDocument.Styles("Heading " & i)
    .ParagraphFormat.LeftIndent = CentimetersToPoints(i * 1.25 - 1.25)
    .ParagraphFormat.FirstLineIndent = CentimetersToPoints(-1.25)
    .Font.Name = "Gill Sans MT"
    .Font.Italic = False
    .Font.Bold = False
    .Font.ColorIndex = wdAuto
    .Font.Size = 17 - i
  End With
Next
End Sub
The code I previously posted also assumed your document was manually numbered. As it is auto-numbered, use:

Code: Select all

Sub ApplyHeadingStyles()
Dim Para As Paragraph, Rng As Range
With ActiveDocument.Range
  For Each Para In .Paragraphs
    With Para.Range
      If .ListFormat.ListString <> "" Then
        .Style = "Heading " & .ListFormat.ListLevelNumber
      End If
    End With
  Next
End With
End Sub
Last edited by macropod on 04 May 2021, 21:33, edited 1 time in total.
Paul Edstein
[Fmr MS MVP - Word]

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Thank you Paul. This will work nicely.

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Hi Paul,

Hope I can ask a follow-up question.

How can the next section restart with I.?

Right now on the attached doc, the next section continuous from the previous, so it's, starting with III.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Convert outline to a multilevel list

Post by macropod »

Simply go to Home|Paragraph>Numbering>Set Number Value and choose '1'.
Paul Edstein
[Fmr MS MVP - Word]

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Maybe I'm not quite understanding and missing the big picture, but wouldn't this still be a manual process?
I can do this fine by selecting Restart with I., but this gets a little wearisome after 70+ outlines.

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Convert outline to a multilevel list

Post by Charles Kenyon »

Then move your list entries down one level and use a non-numbered level at the top to restart numbering.

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Hi Charles, thanks for the follow-up. I think I have it all sorted now.

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Convert outline to a multilevel list

Post by macropod »

gailb wrote:
10 May 2021, 00:39
Maybe I'm not quite understanding and missing the big picture, but wouldn't this still be a manual process?
I can do this fine by selecting Restart with I., but this gets a little wearisome after 70+ outlines.
I was working from the implications of your previous post, which seems to suggest some sections have more than one Heading 1 paragraph, viz:
gailb wrote:
09 May 2021, 02:21
Right now on the attached doc, the next section continuous from the previous, so it's, starting with III.
If the Section you want to re-start at I is III rather than II, the implication is that the II is to be retained. In that case, it's impossible for Word to know when you want to re-start and when you don't
Paul Edstein
[Fmr MS MVP - Word]

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Convert outline to a multilevel list

Post by gailb »

Right now, every outline is separated by a page break. Can this be considered a section and then each section would restart with I.?

Also, each new outline starts with the words Detailed Notes.