Sunday, April 20, 2008

Tip # 36 Identify printed sheets

Printing a sheet is a common task. Some users find it useful to print the name of the workbook in the header or footer. In Excel 2003, you can accomplish this by choosing Page Setup from the File menu and clicking the Header/Footer tab. Then, choose the appropriate item from the Header control's drop-down list. Versions prior to 2003 can use the following VBA procedure to print the full file's pathname:
Sub FormatHeader() 
With ThisWorkbook

ThisWorkbook.Worksheets(sheetname)PageSetup.LeftHeader = .FullName

End With

End Sub


where sheetname is the sheet's name as a string value. To make the procedure more dynamic, use ActiveSheet.Name instead. That way you can run it against any sheet in the workbook.