Microsoft KB Archive/272717

= XL2000: How To Add the Workbook Path to the Title Bar =

Article ID: 272717

Article Last Modified on 7/4/2007

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q272717



SUMMARY
This article provides a sample Microsoft Visual Basic for Applications macro that adds the workbook path and file name to the title bar of a workbook when opening or saving a file.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

Sample Code
To add the saved document file name and path to the title bar of the active document, follow these steps:  Save and close any open workbooks, and then create a new workbook. Start the Visual Basic Editor (press ALT+F11). On the Insert menu, click Module.  Type the following code in the module: Sub SaveAser Application.Dialogs(xlDialogSaveAs).Show Application.ActiveWindow.Caption = ActiveWorkbook.FullName End Sub

Sub Saver 'Checks to see if the file has been saved by looking 'for a colon in the FullName, which includes any path. If InStr(1, ActiveWorkbook.FullName, &quot;:&quot;) > 0 Then 'File has been saved. Show the Save dialog box and 'put path in caption. ActiveWorkbook.Save Application.ActiveWindow.Caption = ActiveWorkbook.FullName Else 'file has not been saved. Show SaveAs dialog box and 'put path in caption. Application.Dialogs(xlDialogSaveAs).Show Application.ActiveWindow.Caption = ActiveWorkbook.FullName End If  End Sub

Sub Opener Application.Dialogs(xlDialogOpen).Show Application.ActiveWindow.Caption = ActiveWorkbook.FullName End Sub  Press ALT+F11 to return to Microsoft Excel.

Using the Macro to Open a File
To open an existing file, follow these steps:
 * 1) On the Tools menu, point to Macro, and then click Macros.
 * 2) Click Opener and then click Run.
 * 3) In the Open dialog box, select the Excel file you want to open and then click Open.

The full path and file name will appear in the title bar of the opened workbook.

Using the Macro to Save a File
To save a new file, follow these steps:
 * 1) On the Tools menu, point to Macro, and then click Macros.
 * 2) Click Saver and then click Run.
 * 3) In the Save dialog box, select the location where you want to save the file and click Save.

The full path and file name will appear in the title bar of the saved workbook.

Running the Macro Automatically When You Start Excel
To run the macro automatically when you start Excel, save the workbook with the new code in the Xlstart folder.

Assigning the Macros to Toolbar Buttons
To customize Excel and assign the macros to the built-in toolbar buttons, follow these steps:
 * 1) Start Excel.
 * 2) On the Tools menu, click Customize.
 * 3) In the Customize dialog box, click the Commands tab.
 * 4) On the Standard toolbar above, click the Save button.
 * 5) In the Customize dialog box, click Modify Selection.

A menu appears with different options for your toolbar buttons.
 * 1) Click Assign Macro. In the Macro Name list, click Saver. Click OK.
 * 2) On the Standard toolbar, click the Open button.
 * 3) In the Customize dialog box, click Modify Selection.
 * 4) Click Assign Macro. In the Macro Name list, click Opener. Click OK.

Assigning the Macros to Built-in Menus
To assign these macros to the built-in commands on the File menu, follow these steps:
 * 1) Start Excel.
 * 2) On the Tools menu, click Customize.
 * 3) In the Customize dialog box, click the Toolbars tab.
 * 4) Click to select the Worksheet Menu Bar if it is not already checked.
 * 5) On the File menu, click Open.
 * 6) In the Customize dialog box, click the Commands tab.
 * 7) In the Customize dialog box, click Modify Selection.
 * 8) Click Assign Macro. In the Macro Name list, click Opener. Click OK.
 * 9) On the File menu, click Save.
 * 10) In the Customize dialog box, click the Commands tab.
 * 11) In the Customize dialog box, click Modify Selection.
 * 12) Click Assign Macro. In the Macro Name list, click Saver. Click OK.
 * 13) On the File menu, click Save.
 * 14) In the Customize dialog box, click Modify Selection.
 * 15) Click Assign Macro. In the Macro Name list, click SaveAser. Click OK.
 * 16) In the Customize dialog box, click Close.

Having the Macros Available the Next Time You Start Excel
To have the macros available when you start Excel, hide the workbook. To do this, click Hide on the Windows menu. When you click Exit on the File menu, click Yes if you are prompted to save changes to the hidden workbook.

