FileOpen Command Requires CHR$(34) with Long Filenames

Last reviewed: February 5, 1998
Article ID: Q121856
The information in this article applies to:
  • Microsoft Word for Windows NT, version 6.0

SYMPTOMS

If your macro contains a FileOpen command to open a file with a long filename that contains spaces (for example, FileOpen .Name = "This is a long doc name.doc"), you receive the error message

   This file could not be found <filename>

for each word within the quotation marks.

This behavior also occurs when you are using a variable, as in the following example:

   A$ = "This is a long doc name.doc"
   FileOpen .Name = a$

CAUSE

Word interprets each word within the quotation marks as a single file and cannot find the files because they do not exist. You can specify multiple filenames inside the quotation marks to open several files at once.

RESOLUTION

You can modify the FileOpen command by adding the CHR$(34) to indicate the beginning and end of the long filename. This allows Word to interpret all of the text as a single filename. Using the above example, your command would appear as follows:

   FileOpen .Name = CHR$(34) + "This is a long doc name.doc" + CHR$(34)

If the filename is contained in the variable A$, the correct FileOpen command would be:

   FileOpen .Name = Chr$(34) + A$ + Chr$(34)

STATUS

This behavior is by design.


KBCategory: kbusage
KBSubcategory: kbmacro
Additional reference words: ntword wordnt long file names nt word winword
word6 6.0 macro wordbasic cannot find file fileopen
Keywords : kbmacro
Version : 6.0
Platform : WINDOWS


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: February 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.