Microsoft KB Archive/176699

= "Cannot Access" Error Saving File to 'C' on a Macintosh Computer =

Article ID: 176699

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q176699



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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. 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 XL

Keywords: kbcode kberrmsg kbprb kbprogramming KB176699

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.