Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Assigning a Macro to a Keyboard Combination
Hiding Rows Based on a Cell Value
Excel includes a worksheet function (ROMAN) that allows you to convert Arabic numbers into Roman numerals. You may wonder if there is any such function that allows you to print Roman numerals as page numbers on a printout.
There is no built-in feature that allows you to do that, but you can create a macro that will do the trick. Consider the following macro:
Sub RomanPageNums()
Dim iPages As Integer
Dim J As Integer
' Get count of pages in active sheet
iPages = ExecuteExcel4Macro("Get.Document(50)")
' Print worksheet, page by page
With ActiveSheet
For J = 1 To iPages
' Set page letter
.PageSetup.CenterFooter = _
Application.WorksheetFunction.Roman(J)
' Print page J
.PrintOut From:=J, To:=J
Next J
End With
End Sub
This macro first figures out how many pages are in your printout, and assigns the value to the iPages variable. It then steps through each page, changing the page number in the center portion of the footer prior to printing each page. The page number is set by converting the current page number (J) to a Roman numeral using the ROMAN worksheet function.
If you want the Roman numerals to appear in other parts of the footer, you can replace the .CenterFooter property with either .LeftFooter or .RightFooter. You can also use .LeftHeader, .CenterHeader, or .RightHeader, if desired.
The code in the RomanPageNums macro works in all the recent versions of Excel. If you are using Excel 2000 or greater, you could also replace the actual line that sets the footer with the following code:
.PageSetup.CenterFooter = Application.Roman(J)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2518) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Save Time! ExcelTips has been published weekly since late 1998. Past issues of ExcelTips are available in convenient ExcelTips archives. Have your own enhanced archive of ExcelTips at your fingertips, available to use at any time!