mancubus
04-10-2014, 02:00 PM
hi all.
a have a number of inherited documents written as a plain text. a sample is included in the attached "before.docm" file.
headings are indicated by "(Hx)" (x being the heading level) in front of the line.
i found a FR code, adopted it to convert these lines into headings.
Sub Apply_Headings()
Application.ScreenUpdating = False
For i = 1 To 4
With ActiveDocument.Content.Find
.ClearFormatting
.Text = "(H" & i & ")"
With .Replacement
.Text = "^&"
.ClearFormatting
.Style = Choose(i, wdStyleHeading1, wdStyleHeading2, wdStyleHeading3, wdStyleHeading4)
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Next
Application.ScreenUpdating = True
End Sub
as can be seen in after.docm file, it does -more or less- what i expect for H1, H3 and H4's. but for H2's, it applies completely different format. i think it is because of preset H2 format of overwritten old document.
i recorded a macro while manually changing the Current H2 format:
Font: (Default) +Headings (Cambria), 12 pt, Font color: Accent 2, All caps, English (United States), Expanded by 0,75 pt, Centered
Line spacing: Multiple 1,05 li, Space
Before: 20 pt, Level 2, Border:
Bottom: (Single solid line, Accent 2, 0,5 pt Line width), Style: Linked, Hide until used, Show in the Styles gallery, Priority: 10
Based on: Normal
Following style: Normal
to Desired H2 format:
Font: (Default) Arial, 12 pt, Bold, Font color: Accent 1, All caps, English (United States), Expanded by 0,75 pt
Line spacing: Multiple 1,05 li, Space
Before: 20 pt, Level 2, Border:
Bottom: (Single solid line, Accent 2, 0,5 pt Line width), Style: Linked, Automatically update, Hide until used, Show in the Styles gallery, Priority: 10
Based on: Normal
Following style: Normal
here is what i get:
Sub Macro1()
With ActiveDocument.Styles("Heading 2").Font
.Name = "Arial"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = True
.Color = -738131969
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0.75
.Scaling = 100
.Kerning = 0
.Animation = wdAnimationNone
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
With ActiveDocument.Styles("Heading 2").ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 20
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.05)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevel2
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.CollapsedByDefault = False
End With
ActiveDocument.Styles("Heading 2").NoSpaceBetweenParagraphsOfSameStyle = _
False
With ActiveDocument.Styles("Heading 2")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
End Sub
the problem is i cant see an option to remove border (red bolded part).
what i need are:
- change the H2's formats similar to H1, H3, H4's format as i did manually but without bottom border line.
- change "(Hx)"s to incrementing numbers for each level,
- simplify the recorded macro by removing default parameter lines.
- insert a TOC starting at page2.
any help is highly appreciated.
thanks.
a have a number of inherited documents written as a plain text. a sample is included in the attached "before.docm" file.
headings are indicated by "(Hx)" (x being the heading level) in front of the line.
i found a FR code, adopted it to convert these lines into headings.
Sub Apply_Headings()
Application.ScreenUpdating = False
For i = 1 To 4
With ActiveDocument.Content.Find
.ClearFormatting
.Text = "(H" & i & ")"
With .Replacement
.Text = "^&"
.ClearFormatting
.Style = Choose(i, wdStyleHeading1, wdStyleHeading2, wdStyleHeading3, wdStyleHeading4)
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Next
Application.ScreenUpdating = True
End Sub
as can be seen in after.docm file, it does -more or less- what i expect for H1, H3 and H4's. but for H2's, it applies completely different format. i think it is because of preset H2 format of overwritten old document.
i recorded a macro while manually changing the Current H2 format:
Font: (Default) +Headings (Cambria), 12 pt, Font color: Accent 2, All caps, English (United States), Expanded by 0,75 pt, Centered
Line spacing: Multiple 1,05 li, Space
Before: 20 pt, Level 2, Border:
Bottom: (Single solid line, Accent 2, 0,5 pt Line width), Style: Linked, Hide until used, Show in the Styles gallery, Priority: 10
Based on: Normal
Following style: Normal
to Desired H2 format:
Font: (Default) Arial, 12 pt, Bold, Font color: Accent 1, All caps, English (United States), Expanded by 0,75 pt
Line spacing: Multiple 1,05 li, Space
Before: 20 pt, Level 2, Border:
Bottom: (Single solid line, Accent 2, 0,5 pt Line width), Style: Linked, Automatically update, Hide until used, Show in the Styles gallery, Priority: 10
Based on: Normal
Following style: Normal
here is what i get:
Sub Macro1()
With ActiveDocument.Styles("Heading 2").Font
.Name = "Arial"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = True
.Color = -738131969
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0.75
.Scaling = 100
.Kerning = 0
.Animation = wdAnimationNone
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
With ActiveDocument.Styles("Heading 2").ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 20
.SpaceBeforeAuto = False
.SpaceAfter = 10
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceMultiple
.LineSpacing = LinesToPoints(1.05)
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevel2
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.CollapsedByDefault = False
End With
ActiveDocument.Styles("Heading 2").NoSpaceBetweenParagraphsOfSameStyle = _
False
With ActiveDocument.Styles("Heading 2")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
End Sub
the problem is i cant see an option to remove border (red bolded part).
what i need are:
- change the H2's formats similar to H1, H3, H4's format as i did manually but without bottom border line.
- change "(Hx)"s to incrementing numbers for each level,
- simplify the recorded macro by removing default parameter lines.
- insert a TOC starting at page2.
any help is highly appreciated.
thanks.