Macro to Insert Filename with Path Information

ID: 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$ + "\" + 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$ + "\" + B$
   ClosePane
   End Sub 
In this macro, change the line "ViewHeaderFooter" to "ViewHeaderFooter .type=1" 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$ + "\" + 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.


REFERENCES

"Microsoft Word for Windows User's Reference," page 96
"Microsoft Word for Windows Technical Reference," page 46
"Microsoft Word for Windows and OS/2 Technical Reference," pages 163-164

Additional query words: 1.x 2.0 winword2 winword directory edit summary full complete location macword

Keywords :
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c
Platform : WINDOWS
Issue type :


Last Reviewed: October 4, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.