View Single Post
 
Old 07-12-2022, 01:28 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Dec 2020
Posts: 171
Shelley Lou is on a distinguished road
Default VBA Change to correct Heading style

Hi Macropod, thank you so much for the update. I still can't seem to get the second macro 'ApplyHeadingStyles_Auto' to work - it has a compile error Sub or Function not defined and highlights the word 'Undo' in the line If bLvl = False Then Undo - should I have a particular Sub or Function in a module to get this to work?

I have modified the first macro slightly to get it to work. The line .Font.Bold = Choose(i, 1, 1, 0, 0, 0, 0) was still making the heading number bold so I changed this to .Font.Bold = Choose(i, 0, 0, 0, 0, 0, 0) and that seems to have worked.

I also needed the paragraphs to have Hanging Indents. I recorded the steps first to get the values .ParagraphFormat.FirstLineIndent = InchesToPoints(-0.5) so after trying many variations I've come up with this code which seems to work.

Code:
With ActiveDocument.Styles("Heading " & i)
   Select Case i
      Case 1, 2
         .ParagraphFormat.LeftIndent = InchesToPoints(0.5)
         .ParagraphFormat.FirstLineIndent = InchesToPoints(-0.5)
      Case 3
         .ParagraphFormat.LeftIndent = InchesToPoints(1)
         .ParagraphFormat.FirstLineIndent = InchesToPoints(-0.5)
      Case 4
         .ParagraphFormat.LeftIndent = InchesToPoints(1.5)
         .ParagraphFormat.FirstLineIndent = InchesToPoints(-0.5)
      Case 5
        .ParagraphFormat.LeftIndent = InchesToPoints(2)
        .ParagraphFormat.FirstLineIndent = InchesToPoints(-0.5)
      Case 6
        .ParagraphFormat.LeftIndent = InchesToPoints(2.5)
        .ParagraphFormat.FirstLineIndent = InchesToPoints(-0.5)
    End Select
Reply With Quote