Pentru a insera numărul de pagină în orice celula dintr-o foaie excel, procedăm astfel:

foaie excel->CTRL+F11->INSERT->MODULE->copiem codul de mai jos->în celula în care dorim să introducem nr. de pagina inserăm: =pagenumber()

Public Function PageNumber( _

Optional ByRef rng As Excel.Range) As Variant

Dim pbHorizontal As HPageBreak

Dim pbVertical As VPageBreak

Dim nHorizontalPageBreaks As Long

Dim nVerticalPageBreaks As Long

Dim nPageNumber As Long

On Error GoTo ErrHandler

Application.Volatile

If rng Is Nothing Then _

Set rng = Application.Caller

With rng

If .Parent.PageSetup.Order = xlDownThenOver Then

nHorizontalPageBreaks = .Parent.HPageBreaks.Count + 1

nVerticalPageBreaks = 1

Else

nHorizontalPageBreaks = 1

nVerticalPageBreaks = .Parent.VPageBreaks.Count + 1

End If

nPageNumber = 1

For Each pbHorizontal In .Parent.HPageBreaks

If pbHorizontal.Location.Row > .Row Then Exit For

nPageNumber = nPageNumber + nVerticalPageBreaks

Next pbHorizontal

For Each pbVertical In .Parent.VPageBreaks

If pbVertical.Location.Column > .Column Then Exit For

nPageNumber = nPageNumber + nHorizontalPageBreaks

Next pbVertical

End With

PageNumber = nPageNumber

ResumeHere:

Exit Function

ErrHandler:

‘Could use much more error handling…!

PageNumber = CVErr(xlErrRef)

Resume ResumeHere

End Function

Obs.: se salveaza fişierul excel, în fişier excel care accepta macrocomezi.

Link sursă: http://answers.microsoft.com/thread/ebfb5b62-b624-4503-a142-6dea1ba813f9