Forum Discussion
In Microsoft Word headers, how do I enter content that differs on each page without section breaks?
Well from reading the previous replies, it should be obvious that you simply can't have unique headers on each page of a document without using section breaks.
Can I assume that your devotional book is finished. I mean that you have a document containing 365 pages (one page per day)? If yes, the following may meet your requirements:
The macro loops through each page of the document and inserts a textbox (that appears to be in the header) and serves as a unique header for each page. Now, the problem is if your book isn't actually finished and you start moving text around, adding text or deleting text, then these textboxes will be relocated (and out of place). In that case you will have to run the ScrollByPage procedure again.
Option Explicit
Sub ScrollByPage()
Dim oPage As Page
Dim oStart As Range
Dim oShp As Shape
Dim lngIndex As Long
'Scrolls document by page and inserts a unique pseudo header on each page.
'Delete any existing pseudo headers
For lngIndex = ActiveDocument.Shapes.Count To 1 Step -1
Set oShp = ActiveDocument.Shapes(lngIndex)
If InStr(oShp.Name, "DTB") = 1 Then
oShp.Delete
End If
Next
Set oStart = ActiveDocument.Range(0, 0)
For Each oPage In ActiveDocument.ActiveWindow.ActivePane.Pages
oPage.Rectangles(1).Range.Select
Selection.Collapse wdCollapseStart
DoEvents
AddTextboxAndAssignToShape
Next oPage
oStart.Select
lbl_Exit:
Exit Sub
End Sub
Sub AddTextboxAndAssignToShape()
Dim shpTextBox As Shape
Set shpTextBox = ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=70, Top:=25, Width:=200, Height:=25)
shpTextBox.Name = "DTB" & ActiveDocument.Shapes.Count
With shpTextBox
.TextFrame.TextRange.Text = "Crumbs ~ " & Format(DateAdd("d", Selection.Information(wdActiveEndPageNumber) - 1, Year(Now) & "/1/1"), "MMMM dd") & " / Day " & Selection.Information(wdActiveEndPageNumber)
.Line.Visible = msoFalse
End With
lbl_Exit:
Exit Sub
End Sub