Knowledge Base

XL2000: Run-time Error 1004 When You Save Workbook as Text

Article ID: 199268

Article Last Modified on 11/5/2003


APPLIES TO


This article was previously published under Q199268

SYMPTOMS

When you run a Microsoft Visual Basic for Applications macro that saves a workbook as text, you may receive the following error message:
Run-time error '1004':

Method 'SaveAs' of object '_Workbook' failed"

CAUSE

This error message occurs when the following conditions are true:

The Lock project for viewing option is selected in the Visual Basic for Applications project.

-and-

You run a macro that uses the .SaveAs method and the FileFormat argument is set to xlText.

WORKAROUND

To work around this problem, unlock the workbook before running the macro. To do this, follow these steps:
  1. Open the workbook that you are trying to save as text.
  2. Press ALT+F11 to open the Visual Basic Editor.
  3. On the Tools menu, click VBAProject Properties, and then click the Protection tab.
  4. Click to clear the Lock project for viewing check box. Click OK.
  5. On the File menu, click Save. Press ALT+Q to return to Excel.
The macro should now run properly and save the workbook as a text file.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: XL2000 Run-time error 1004 Method SaveAs of object _Workbook failed

Keywords: kberrmsg kbbug kbpending KB199268