"Cannot Access" Error Saving File to 'C' on a Macintosh Computer (176699)
The information in this article applies to:
- Microsoft Excel 98 Macintosh Edition
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'.
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"
WORKAROUNDMicrosoft 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.
Modification Type: | Minor | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbcode kberrmsg kbprb kbProgramming KB176699 |
---|
|