Search notes:

Office Object Model: Word - Field

A field allows to insert dynamic text (such as current page number or date) into a document.

Inserting a page number

The following VBA code tries to demonstrate how a page number is inserted into a word document:
option explicit

sub main() ' {

    selection.pageSetup.orientation = wdOrientLandscape

    with selection
     '
     ' Make a really big font
     '
     .font.size = 120

     .typeText "This is page number "
     .fields.add selection.Range, text := "page"

     .typeParagraph

     .typeText "This is page number "
     .fields.add selection.Range, text := "page"

    end with

end sub ' }
Github repository about-MS-Office-object-model, path: /Word/Field/pageNumber.bas

See also

Word Object Model

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1738220288, '18.224.68.75', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Word/Object-Model/Field/index(71): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78