XL:Permission Denied, Error 70 When You Use FileCopy Statement

ID: Q147394

The information in this article applies to:

SYMPTOMS

In Microsoft Excel, when you use the FileCopy statement in a Visual Basic for Applications macro, you may receive the following error message:

   Run-time Error '70' Permission Denied

CAUSE

This problem occurs if the source file you want to copy is open when you try to run the macro.

WORKAROUND

You can avoid this problem by using the SaveCopyAs method. If you use the SaveCopyAs method, you can save a copy of the source workbook to a file without modifying the open workbook in memory.

Visual Basic Code Sample

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

To help you work around this problem, use Visual Basic for Applications code similar to the following example:

   Sub copyfile()

      Application.ScreenUpdating=False
      'Define source file name, not including path.
      SourceFile="source.xls"
      'Define target file name. Include path if needed.
      DestinationFile="c:\destin.xls"
      'Copy source to target.
      Workbooks(SourceFile).SaveCopyAs DestinationFile

   End Sub

Additional query words: 5.00 5.00c 7.00 8.00 97
Keywords          : kberrmsg kbprg kbdta kbdtacode KbVBA xlwin 
Version           : WINDOWS:5.0,7.0,97
Platform          : WINDOWS

Last Reviewed: May 17, 1999