I have a footer-text that I need to replace with VBA macros and this is what I am doing:
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
text = Replace(.Range.text, "SITECODE", ws.Cells(24, 2))
text = Replace(text, "STREET", ws.Cells(6, 2))
text = Replace(text, "SITENAME", ws.Cells(18, 2))
text = Replace(text, "POSTALCODE", ws.Cells(2, 2))
text = Replace(text, "Page number:", "Page number: " & wdActiveEndPageNumber)
.Range.text = Replace(text, "CITY", ws.Cells(10, 2))
End With
This works except for one line:
text = Replace(text, "Page number:", "Page number: " & wdActiveEndPageNumber)
The pagenumber is always 3, which is also wrong on the first numbered page 2. How can I add the right number to text. I know that PageNumbers.Add exists but this does not align well with my document footer.