A
avkokin
Hello.
There is Microsoft's article "How to create two page-numbering schemes
in one document in Word 2003 and in Word 2002" on the site
http://support.microsoft.com/kb/291283/en-us. I try create my macro on
basic of it (first method with the field SEQ). But I can't overcome
numbering into header and footer. My head by this time turn. That is
the file as example (http://www.box.net/shared/repk7lsg84), and lower
my code. Please, help me and give me a tip.
Thank you very much.
My code:
Sub twinNumberingPages3()
Dim sec As Section
Dim myRange As Range
Dim myR As Range
Dim nSec As Integer
Dim nIndex As Integer
Dim i As Integer
ActiveWindow.View.ShowFieldCodes = True
nSec = ActiveDocument.Sections.Count
Selection.HomeKey unit:=wdStory
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="seq v1 \h \r "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="sectionpages"
.MoveRight unit:=wdCharacter, Count:=4
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="seq v2 \h \r0"
End With
If nSec > 1 Then
For nIndex = 2 To nSec
ActiveDocument.Sections(nIndex).Range.Select
Selection.Collapse wdCollapseStart
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="seq v1 \c", _
preserveformatting:=False '
Selection.MoveLeft unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="seq v2 \h \r"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="="
Selection.MoveRight unit:=wdCharacter, Count:=5,
Extend:=wdExtend
Selection.Collapse wdCollapseEnd
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="sectionpages", _
preserveformatting:=False
Selection.TypeText Text:="+"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="seq v2 \c", _
preserveformatting:=False
Selection.MoveLeft unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="="
Selection.MoveLeft unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="seq v1 \h \r"
Next nIndex
End If
ActiveDocument.Range.InsertAfter vbCr
Set myR = ActiveDocument.Range
myR.Collapse direction:=wdCollapseEnd
myR.Select
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="seq
v2 \c", preserveformatting:=False
.TypeText Text:="+"
.Fields.Add Range:=Selection.Range, Type:=wdFieldPage,
preserveformatting:=False
.MoveLeft unit:=wdCharacter, Count:=3, Extend:=wdExtend
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="="
.MoveLeft unit:=wdCharacter, Count:=3
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Fields.Update
End With
Selection.Cut
ActiveDocument.Paragraphs.Last.Range.Delete
Selection.HomeKey unit:=wdStory
Set myR =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
myR.Collapse direction:=wdCollapseEnd
myR.Paste
Selection.HomeKey unit:=wdStory
For i = 1 To ActiveDocument.Sections.Count
Set myRange =
ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary).Range
For Each sec In ActiveDocument.Sections
With sec.Headers(wdHeaderFooterPrimary)
.Range.Fields.Add Range:=myRange, Type:=wdFieldPage,
preserveformatting:=False
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = 1
End With
Next sec
Next i
ActiveWindow.View.ShowFieldCodes = False
End Sub
There is Microsoft's article "How to create two page-numbering schemes
in one document in Word 2003 and in Word 2002" on the site
http://support.microsoft.com/kb/291283/en-us. I try create my macro on
basic of it (first method with the field SEQ). But I can't overcome
numbering into header and footer. My head by this time turn. That is
the file as example (http://www.box.net/shared/repk7lsg84), and lower
my code. Please, help me and give me a tip.
Thank you very much.
My code:
Sub twinNumberingPages3()
Dim sec As Section
Dim myRange As Range
Dim myR As Range
Dim nSec As Integer
Dim nIndex As Integer
Dim i As Integer
ActiveWindow.View.ShowFieldCodes = True
nSec = ActiveDocument.Sections.Count
Selection.HomeKey unit:=wdStory
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="seq v1 \h \r "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="sectionpages"
.MoveRight unit:=wdCharacter, Count:=4
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="seq v2 \h \r0"
End With
If nSec > 1 Then
For nIndex = 2 To nSec
ActiveDocument.Sections(nIndex).Range.Select
Selection.Collapse wdCollapseStart
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="seq v1 \c", _
preserveformatting:=False '
Selection.MoveLeft unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="seq v2 \h \r"
Selection.MoveRight unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="="
Selection.MoveRight unit:=wdCharacter, Count:=5,
Extend:=wdExtend
Selection.Collapse wdCollapseEnd
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="sectionpages", _
preserveformatting:=False
Selection.TypeText Text:="+"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="seq v2 \c", _
preserveformatting:=False
Selection.MoveLeft unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="="
Selection.MoveLeft unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_
preserveformatting:=False
Selection.TypeText Text:="seq v1 \h \r"
Next nIndex
End If
ActiveDocument.Range.InsertAfter vbCr
Set myR = ActiveDocument.Range
myR.Collapse direction:=wdCollapseEnd
myR.Select
With Selection
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="seq
v2 \c", preserveformatting:=False
.TypeText Text:="+"
.Fields.Add Range:=Selection.Range, Type:=wdFieldPage,
preserveformatting:=False
.MoveLeft unit:=wdCharacter, Count:=3, Extend:=wdExtend
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
preserveformatting:=False
.TypeText Text:="="
.MoveLeft unit:=wdCharacter, Count:=3
.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Fields.Update
End With
Selection.Cut
ActiveDocument.Paragraphs.Last.Range.Delete
Selection.HomeKey unit:=wdStory
Set myR =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
myR.Collapse direction:=wdCollapseEnd
myR.Paste
Selection.HomeKey unit:=wdStory
For i = 1 To ActiveDocument.Sections.Count
Set myRange =
ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary).Range
For Each sec In ActiveDocument.Sections
With sec.Headers(wdHeaderFooterPrimary)
.Range.Fields.Add Range:=myRange, Type:=wdFieldPage,
preserveformatting:=False
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = 1
End With
Next sec
Next i
ActiveWindow.View.ShowFieldCodes = False
End Sub