CopyFile Command Altered by Hide MS-DOS Extension Option

Last reviewed: February 5, 1998
Article ID: Q134808
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-cd, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Windows 95 operating system, version 7.0

SYMPTOMS

When you use the WordBasic command, CopyFile, the copy of the file does not have an extension. As a result, the copied file loses its association with Microsoft Word and becomes a generic Windows 95 file. The following code results in this problem:

   Sub MAIN
   CopyFile "c:\storage\test.doc", "c:\temp"
   End Sub

CAUSE

This problem occurs when the "Hide MS-DOS file extensions for file types that are registered" is checked in Windows Explorer. (To locate this option, in Windows Explorer, click Options on the View menu.)

STATUS

Microsoft has confirmed this to be a problem in Microsoft Word for Windows 95 version 7.0. This problem was corrected in Word version 7.0a for Windows 95.

RESOLUTION

To work around this problem, use one of the following methods to preserve the copied file's association with Microsoft Word.

Method 1. Make sure the "Hide MS-DOS file extensions for file types that

          are registered" option in Windows Explorer is not checked.

Method 2. Use the Declare command to make a CopyFileA call to
          Kernel32.dll. To do this, use the following macro:

          NOTE: The sample assumes that you have a Microsoft Word document
          called "Test.doc" located in the C:\Storage folder.

          Declare Function CopyFileA Lib "kernel32"(a$ As String, b$ As
          String, n As Integer) As Integer

          Sub MAIN
             x = CopyFileA("c:\storage\test.doc", "c:\temp\test.doc ", 3)
          End Sub

          NOTE: Using a number greater than 0 in the above example will not
          overwrite an existing file. The file specified as the destination
          remains the same. However, if 0 is used, as in the example below,
          the destination file will be overwritten by the specified file if
          it exists in the specified directory.

          Declare Function CopyFileA Lib "kernel32"(a$ As String, b$ As
          String, n As Integer) As Integer

          Sub MAIN
             x = CopyFileA("a:\test.doc", "c:\test.doc ", 0)
          End Sub

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.


KBCategory: kbusage buglist7.0 fixlist7.0a
KBSubcategory: kbmacroexample

Additional reference words: 7.0 word95 copyfile copy file wordbasic
word7 winword word basic macro example 6.0 6.0a 6.0c 7.0 7.0a 2.0
2.0a 2.0a-cd 2.0b 2.0c

Keywords : kbmacroexample
Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a
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.