Microsoft Excel Question:

Download Job Interview Questions and Answers PDF

How can I print a workbooks full path in the header or footer? The Page Setup dialog box does not seem to offer the option.?

MS Excel Interview Question
MS Excel Interview Question

Answer:

For whatever reason, Microsoft continues to ignore what must be thousands of requests for this feature. Although Microsoft Word offers this feature, Excel offers no direct way to print a workbook's full path in the header or footer. The only solution is to create a macro. The technique described below works with Excel 97 and later.

In Excel, press Alt-F11 to activate the Visual Basic editor. In the Project window, double-click the project that corresponds to your workbook. The project list will expand to show several objects. Double-click the item labeled Microsoft Excel Objects, and then double-click the object labeled ThisWorkbook. Enter the following three lines of VBA code into the code module for the ThisWorkbook object (usually in the right pane of the window you're seeing at this point).

Private Sub Workbook_BeforePrint(Cancel As Boolean)

ActiveSheet.PageSetup.LeftHeader = ThisWorkbook.FullName

End Sub

After inserting the code, press Alt-Q to return to Excel.

This procedure will be executed before you print or preview your workbook. It simply inserts the workbook's path into the left header position. If you prefer to put the path in a different position, substitute any of the following for LeftHeader: CenterHeader, RightHeader, LeftFooter, CenterFooter, or RightFooter.

Download MS Excel Interview Questions And Answers PDF

Previous QuestionNext Question
How can I save a chart as a GIF file?How can I enter the current date into a cell so it does not change from day to day? When I use the NOW function, it always shows the current date?