Microsoft KB Archive/71995

{|
 * width="100%"|

Macro to Insert Filename with Path Information

 * }

Q71995

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c

-

SUMMARY
The WordBasic FileName$ function returns the document file name and path. The following macro inserts the document name and path into your document window.

  Sub MAIN a$=FileName$ Insert a$  End Sub However, if the insertion point is positioned within a header or footer, the document file name and path is not inserted. This occurs because the header and footers in Word for Windows are treated as separate windows from the document window. As a result, the FileName$ function does not return the name of the document.

The following macros can be used as alternatives to using the FileName$ function. To determine the document name and directory, the macros access the summary information dialog box and extract the filename and directory information. Word for Windows adds the directory and filename together with a backslash between them with the following macro line:

  Insert A$ + &quot;\&quot; + B$ The path and filename (C:\WINWORD\README.DOC) are inserted at the position of the insertion point.

Word 2.0
The following macro inserts the document file name and path into the document header.

  Sub Main ViewNormal FileSummaryInfo .Update Dim dlg As Dialog FileSummaryInfo GetCurValues dlg A$ = dlg.Directory B$ = dlg.FileName ViewHeaderFooter  'open document header Insert A$ + &quot;\&quot; + B$  ClosePane End Sub In this macro, change the line &quot;ViewHeaderFooter&quot; to &quot;ViewHeaderFooter .type=1&quot; to insert the information into the footer.

Word 1.x
Position the insertion point in the header or footer and run the following macro.

  Sub MAIN EditSummaryInfo .Update Dim dlg As Dialog EditSummaryInfo GetCurValues dlg A$ = dlg.Directory B$ = dlg.FileName Insert A$ + &quot;\&quot; + B$  End Sub The document name and path are inserted at the insertion point. To automate the process entirely, use the EditHeaderFooter command to open the header or footer pane.

  EditHeaderFooter     'header EditHeaderFooter 1  'footer

STATUS
Microsoft has confirmed this to be a problem in Word for Windows, versions 1.x and 2.x. This problem was corrected in Word for Windows, version 6.0.