alexander1113
Programmer
Hi,
Im trying to write a macro in Word in which it goes through every page. On each page it will write the order number as the header. But the problem I'm having is that when I write a header it writes them on all pages. I want to have different headers on each page because each page may have a different order number. I can't write them as footers because then that would totally dissassemble the page breaks which have been created. I have this so far:
For iPgNum = 1 To Selection.Information(wdNumberOfPagesInDocument)
sPgNum = CStr(iPgNum)
' Go to next page in iteration.
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, _
count:=sPgNum
objword = Selection.Words(1).Text
objword = Trim(objword)
Test = StrComp(objword, "New", 0)
If Test = 0 Then
MsgBox "YES " & objword
Set myCell = ActiveDocument.Tables(count).Cell(Row:=1, Column:=1)
myCell = Left$(myCell, Len(myCell) - 2)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = False
Selection.HeaderFooter.Range.Text = myCell
record_count = 1
Else
record_count = record_count + 1
MsgBox record_count
End If
count = count + 3
Next
Im trying to write a macro in Word in which it goes through every page. On each page it will write the order number as the header. But the problem I'm having is that when I write a header it writes them on all pages. I want to have different headers on each page because each page may have a different order number. I can't write them as footers because then that would totally dissassemble the page breaks which have been created. I have this so far:
For iPgNum = 1 To Selection.Information(wdNumberOfPagesInDocument)
sPgNum = CStr(iPgNum)
' Go to next page in iteration.
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, _
count:=sPgNum
objword = Selection.Words(1).Text
objword = Trim(objword)
Test = StrComp(objword, "New", 0)
If Test = 0 Then
MsgBox "YES " & objword
Set myCell = ActiveDocument.Tables(count).Cell(Row:=1, Column:=1)
myCell = Left$(myCell, Len(myCell) - 2)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = False
Selection.HeaderFooter.Range.Text = myCell
record_count = 1
Else
record_count = record_count + 1
MsgBox record_count
End If
count = count + 3
Next