First, you need to get a reference to the word document, then you just use
the automation stuff as you would with VBA, but with some VB.NET syntax.
This example will create a new document and add peage numbers to the header,
aligned to the right. Make sure you add a reference to the Word object
library to your project and import the library at the top of your code.
btw: Word documents have headers and footers by default, they are just not
visible :).
Imports System.Runtime.InteropServices
Imports Word
Dim theWordApplication as Word.Application
Dim theDocument as Word.Document
Try
' Create a new word application
theWordApplication = New Word.Application
' Add a new document, based on this template
theDocument =
m_WordApplication.Documents.Add(Template:=CType(__ whatever_the_template_it_if_you_want_one__,
Object))
' Make the application invisible
theWordApplication.Visible = False ' Make this true to see results while
debugging
' Add page numbers to the document.
Dim wordHeaderIndex As Word.WdHeaderFooterIndex =
WdHeaderFooterIndex.wdHeaderFooterFirstPage
theWordApplication.Sections.Item(1).Headers.Item(w ordHeaderIndex).PageNumbers.Add
( _
PageNumberAlignment:=
Word.WdPageNumberAlignment.wdAlignPageNumberRight, _
FirstPage:= True )
Catch Ex As Exception
' Failed.
Finally
' One thing about Interop, always Try/Catch and cleanup references.
Marshal.ReleaseComObject(theDocument)
Marshal.ReleaseComObject(theWordApplication)
End Try