Hi everyone,
new to forum and word vba, and I very need help.
I have to rearrange a doc file (composed by multiple sections) created by an application from a third party.
I managed to resolve all the problems but pagenumbers in header, given in the form of "Page X of Y".
I have to decide yet if maintaining the native page number format or change it.
In the case I want to maintain the original format, my problem is that the Y is always of 1 minus than total page numbers (if I activate field codes, I get <NUMPAGES -1> and I can't manage to solve it with vba, that is a must).
In the case I want to delete the native format "Page X of Y", I can remove "Page", "X" and "of", but not the same for "Y", which still remains: I've searched in a number of vba forums, but I found only the macro for deleting page numbers, that works for the "X" as I said, but not with the "Y"!
These are the code I use for deleting "Page X of":

Sub cancella()
Dim objSect As Section
Dim objHF As HeaderFooter
Dim objPNum As PageNumber
For Each objSect In ActiveDocument.Sections
For Each objHF In objSect.Headers
For Each objPNum In objHF.PageNumbers
objPNum.Delete
Next
Next
For Each objHF In objSect.Footers
For Each objPNum In objHF.PageNumbers
objPNum.Delete
Next
Next
Next


Call cancellare
End Sub


Sub cancellare()
WordBasic.viewheaderonly
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*" (the * is substitued by "Page" first and by"of" then, because if I use * as wildcard the
macro deletes one char at time only):
.Forward = True
.Wrap = wdFindContinue
.Format = False
End With
If Selection.Find.Execute Then
With Selection
Selection.Delete
End With
End If
End Sub


Very thanks in advance for the precious help!!!