How to Retrieve the Pathname of File

Last reviewed: November 2, 1994
Article ID: Q59774

The information in this article applies to:

  • Microsoft Excel for Windows, versions 2.0, 2.1, 3.0, 4.0, 5.0
  • Microsoft Excel for OS/2, versions 2.2, 3.0

SUMMARY

The DIRECTORY() command can be used in a Microsoft Excel macro to retrieve the drive/directory pathname of the current directory.

In Microsoft Excel, any time the directory is changed from any source, the directory pointer will be changed to reflect the last drive and/or directory selected. The directory pointer is changed even if you choose Cancel (press ESC) in the dialog box (custom or built-in).

Note: The DIRECTORY() command returns only the most recent drive and directory selected, so that a progression through various directories cannot be followed, nor can multiple directories be selected unless you choose OK (press ENTER) between selections and the macro calls the dialog box for each new directory to be selected.

In a Microsoft Excel macro, the DIRECTORY() command can be used after the DIALOG.BOX() command to retrieve the current directory that has been changed by a custom dialog box.

Example:

=DIALOG.BOX(dialog_ref) =DIRECTORY()

Another technique, useful when you open files, is to use the GET.DOCUMENT(2) command, which returns the directory of the active document. After an OPEN() operation, the active document is the document just opened, so that GET.DOCUMENT(2) returns the active drive/directory.

These steps can also be used in Microsoft Excel version 5.0 by using the macros from version 4.0 in a macro sheet.


KBCategory: kbusage
KBSubcategory:

Additional Reference Words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.0
3.00 4.0 4.00 4.0a 4.00a 5.0 5.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.