It's called Word VBA (Visual Basic for Applications). It's part of the default installation and the common term is for such code is "macros". Which is a bit simplified - VBA can perform very complex tasks.
What you describe in the question to which you link (knowing on which page data is located) can be done using Word VBA but
- there is no event that triggers when Word generates a new page due to page content "overflowing"
- it's important to realize that when a document is opened in another configuration (different machine, different printer, different printer driver...) it may not lay-out exactly the same - page and line breaks might be positioned differently.
- How Word controls page layout (whether a cell's content or all the lines in a paragraph must stay together on a page) can be controlled through formatting commands. It would be advisable to learn about these (end-user venue!) before proceding with generating documents.
- Use styles, not direct formatting, for generating Word document content.