
Trong Excel để chèn số trang vào Header hoặc Footer rất là đơn giản . Nhưng để chèn số trang vào một ô bất kì nào đó lại cần phải sử dụng Macro .
Cách thức như sau . Mở File Excel cần làm , bấm tổ hợp phím ALT-F11 để mở cửa sổ Microsoft Visual Basic .
Bấm chọn menu Insert --> Module , chèn macro có nội dung bên dưới
Sub pagenumber()
Dim xVPC As Integer
Dim xHPC As Integer
Dim xVPB As VPageBreak
Dim xHPB As HPageBreak
Dim xNumPage As Integer
xHPC = 1
xVPC = 1
If ActiveSheet.PageSetup.Order = xlDownThenOver Then
xHPC = ActiveSheet.HPageBreaks.Count + 1
Else
xVPC = ActiveSheet.VPageBreaks.Count + 1
End If
xNumPage = 1
For Each xVPB In ActiveSheet.VPageBreaks
If xVPB.Location.Column > ActiveCell.Column Then Exit For
xNumPage = xNumPage + xHPC
Next
For Each xHPB In ActiveSheet.HPageBreaks
If xHPB.Location.Row > ActiveCell.Row Then Exit For
xNumPage = xNumPage + xVPC
Next
ActiveCell = "Page " & xNumPage & " of " & Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
End Sub
Chuyển sang Excel và chọn ô bạn muốn hiển thị rồi chạy macro này là được .