Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q199268

↑ Back to the top


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"

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

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

↑ Back to the top


Keywords: KB199268, kbpending, kbbug, kberrmsg

↑ Back to the top

Article Info
Article ID : 199268
Revision : 3
Created on : 11/5/2003
Published on : 11/5/2003
Exists online : False
Views : 280