Hi,

I am having difficulty getting a piece of code to put page 1 of X, page 2 of X etc automatically through VB. At the moment it just puts the last page X of X down.

I need to amend different documents automatically:-

This is the code that I have used:-
Sub GetHeadersFooters(sFile As String, strfilename As String, text As String, strProjName As String)

Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim oSec As Word.Section
Dim oPageStart As Word.Range
Dim iPage As Integer, iTotalPages As Integer, iSection As Integer
Dim sHeader As String, sFooter As String
Dim strRest As String
Dim pic As Word.Shape




'Open the document
Set oApp = New Word.Application
Set oDoc = oApp.Documents.Open(sFile)
iTotalPages = oDoc.ComputeStatistics(wdStatisticPages)

oApp.Visible = True
'Retrieve the headers and footers on each page
With oDoc

iSection = 0

For iPage = 1 To iTotalPages

'Go to the page represented by the page number iPage and
'retrieve its section
Set oPageStart = oDoc.GoTo(What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=iPage)

Set oSec = oPageStart.Sections(1)

'If this is a different section than the one in the previous
'iteration and it has a first page header/.footer, then
'retrieve the first page header/footer for this section.
'Otherwise, retrieve the primary header/footer for this section
If (iSection < oSec.Index) And _
(oSec.PageSetup.DifferentFirstPageHeaderFooter) Then
sFooter = ""
sHeader = ""
sHeader = oSec.Headers(wdHeaderFooterFirstPage).Range.text
sHeader = " Operations and Maintenance Manual for: " & strProjName
sHeader = oSec.Headers(wdHeaderFooterPrimary).Range.text
sFooter = oSec.Footers(wdHeaderFooterPrimary).Range.text
sFooter = strfilename & " " & text & " Page " & iPage & " of " & iTotalPages
oSec.Headers(wdHeaderFooterPrimary).Range.text = sHeader
oSec.Footers(wdHeaderFooterPrimary).Range.text = sFooter
Else
sFooter = ""
sHeader = ""
sHeader = oSec.Headers(wdHeaderFooterFirstPage).Range.text
sHeader = " Operations and Maintenance Manual for: " & strProjName
sFooter = oSec.Footers(wdHeaderFooterPrimary).Range.text
sFooter = strfilename & " " & text & " Page " & iPage & " of " & iTotalPages
oSec.Headers(wdHeaderFooterPrimary).Range.text = sHeader
oSec.Footers(wdHeaderFooterPrimary).Range.text = sFooter
End If

iSection = oSec.Index



Next

End With

'Make Word visible to compare the document with the results in the


oDoc.Save
oApp.Quit

End Sub

Thanks for any help.