L
LEU
I have the following macro that creates a TOC. When I save the document,
close it and reopen it the indents on “TOC3†have changed. They have gone
from 0.5 to 0.31. The indents on “TOC1†and “TOC2†don’t change. Any ideas on
why this would be happing?
With ActiveDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 1").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 6
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 1").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument.Styles("TOC 2")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 2").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 6
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevel2
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 2").NoSpaceBetweenParagraphsOfSameStyle = True
With ActiveDocument.Styles("TOC 3")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 3").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevel2
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 3").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1,
UseFields:=True, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=False, HidePageNumbersInWeb:=True,
UseOutlineLevels:= _
True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
close it and reopen it the indents on “TOC3†have changed. They have gone
from 0.5 to 0.31. The indents on “TOC1†and “TOC2†don’t change. Any ideas on
why this would be happing?
With ActiveDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 1").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 6
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 1").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument.Styles("TOC 2")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 2").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 6
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevel2
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 2").NoSpaceBetweenParagraphsOfSameStyle = True
With ActiveDocument.Styles("TOC 3")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 3").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevel2
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 3").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1,
UseFields:=True, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=False, HidePageNumbersInWeb:=True,
UseOutlineLevels:= _
True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With