XL: "Cannot Access" Error Saving File to 'C' on a Macintosh

ID: Q176699

The information in this article applies to:

SYMPTOMS

In the versions of Microsoft Excel listed at the beginning of this article, if you run a Microsoft Excel macro or a Visual Basic for Applications macro, you may receive an error message similar to either of the following:

   Run-time error '1004':
   Cannot access 'C'.

    -or-

   Run-time error '1004':
   Microsoft Excel cannot access the file 'C'. There are several possible
   reasons:

   - The file name or path name does not exist.

   - The file you're trying to open is being used by another program.
     Close the document in the other program, and try again.

   - The name of the workbook you're trying to save is the same as the
     name of another document that is read-only. Try saving the workbook
     with a different name.

CAUSE

This problem may occur if the macro contains code that saves a workbook by using an MS-DOS path and file name, as in the following examples:

   =SAVE.AS("C:\Data\Test.xls")

   ActiveWorkbook.SaveAs "C:\Data\Test.xls"

WORKAROUND

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/supportnet/refguide/ 

To work around this problem, make sure that your macro is designed to account for differences between the Microsoft Windows and Macintosh operating systems.

One way to do this is to use the Application.OperatingSystem property to determine whether you are on a computer running Windows or on a computer running the Macintosh operating system, for example:

   Sub CheckOS()

       ' OS equals "Mac" if this is a Macintosh, "Win" if this is a
       ' computer running Windows or Windows NT.
       OS = Left(Application.OperatingSystem, 3)

       If OS = "Win" Then

           ' Use a valid Windows path.
           ActiveWorkbook.SaveAs "C:\Data\Test.xls"

       ElseIf OS = "Mac" Then

           ' Use a valid Macintosh path.
           ActiveWorkbook.SaveAs "Data:Test.xls"

       End If

   End Sub

If you are using the Microsoft Excel (XLM) macro language, the code to use is the following:

   OS=LEFT(GET.WORKSPACE(1),3)
   =IF(OS="Win")
   =SAVE.AS("C:\Data\Test.xls")
   =ELSE.IF(OS="Mac")
   =SAVE.AS("Data:Test.xls")
   =END.IF()
   =RETURN()

STATUS

This behavior is by design of the versions of Microsoft Excel listed at the beginning of this article.

MORE INFORMATION

In Microsoft Windows and Microsoft Windows NT, path names for files include both colons (:) and backslashes (\), for example:

   C:\Data\Test.xls

The colon separates the disk drive letter from the remainder of the path, which uses backslashes to separate folder names from the file name.

On the Macintosh, path names for files use only colons, for example:

   Data:Test.xls

If you attempt to use a MS-DOS file name in a macro on the Macintosh, you may receive an error message similar to one of those in the "Symptoms" section in this article. This behavior occurs because the folder name "C" (from "C:\Data\Test.xls") usually does not exist on a hard disk on a Macintosh computer.

Additional query words: XL5 offvba

Keywords          : kbcode kberrmsg kbprg xlvbainfo 
Version           : MACINTOSH:5.0,5.0a,98
Platform          : MACINTOSH
Issue type        : kbprb

Last Reviewed: May 18, 1999