A
andreas
Hello,
I got a long word document with 8 sections. Almost all of the sections
contain headings level 1,2 and 3. Two of the sections only contain a
heading 1 level.
I now would like to write a macro that automatically finds the
sections where there is only a heading 1 level and set the headers for
these sections automatically.
FOR EXAMPLE, say Section 4 and 7 each contain one heading level 1 and
no headings
level 2 and 3.
The macro should first find these sections (section 4 and 7) and then
with this information do the following (the below part of the macro is
working fine):
Set sect = ActiveDocument.Sections(4)
Set rng = sect.Headers(wdHeaderFooterPrimary).Range
sect.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"STYLEREF ""Heading 1"" "
rng.Collapse wdCollapseEnd
rng.Text = vbTab
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"PAGE \* Roman "
Set sect = ActiveDocument.Sections(7)
Set rng = sect.Headers(wdHeaderFooterPrimary).Range
sect.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"STYLEREF ""Heading 1"" "
rng.Collapse wdCollapseEnd
rng.Text = vbTab
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"PAGE \* Roman "
Help is much appreciated. Thank you in advance
Regards,
Andreas
I got a long word document with 8 sections. Almost all of the sections
contain headings level 1,2 and 3. Two of the sections only contain a
heading 1 level.
I now would like to write a macro that automatically finds the
sections where there is only a heading 1 level and set the headers for
these sections automatically.
FOR EXAMPLE, say Section 4 and 7 each contain one heading level 1 and
no headings
level 2 and 3.
The macro should first find these sections (section 4 and 7) and then
with this information do the following (the below part of the macro is
working fine):
Set sect = ActiveDocument.Sections(4)
Set rng = sect.Headers(wdHeaderFooterPrimary).Range
sect.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"STYLEREF ""Heading 1"" "
rng.Collapse wdCollapseEnd
rng.Text = vbTab
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"PAGE \* Roman "
Set sect = ActiveDocument.Sections(7)
Set rng = sect.Headers(wdHeaderFooterPrimary).Range
sect.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"STYLEREF ""Heading 1"" "
rng.Collapse wdCollapseEnd
rng.Text = vbTab
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
"PAGE \* Roman "
Help is much appreciated. Thank you in advance
Regards,
Andreas