XL7: "Run-time error '1004'" Using SetBackgroundPicture Method

ID: Q131396


The information in this article applies to:
  • Microsoft Excel for Windows 95, version 7.0


SYMPTOMS

In Microsoft Excel, when you run a Visual Basic macro that contains the SetBackgroundPicture method, you may receive the following error message

Run-time error '1004':

Cannot use that command on a protected sheet
even if you did not use the command on a protected worksheet.


CAUSE

This error message appears if you apply the SetBackgroundPicture method to a DialogSheet in a Visual Basic macro, regardless of whether the sheet is protected. For example, the error message described above appears when you run a macro that contains the following command:


   DialogSheets(1).SetBackgroundPicture ("") 
You can use the SetBackgroundPicture method to set the background graphic for a worksheet or chart. Because the SetBackgroundPicture method applies only to the Worksheet object and the Chart object, you should receive an error message when you use the SetBackgroundPicture method with the DialogSheet object. However, the error message that should appear in this case (if the dialog sheet is not protected) is the following:
Run-time error '1001':

DialogSheet does not have SetBackgroundPicture method
Note that this error message correctly appears when you use the SetBackgroundPicture method with a Module object.


RESOLUTION

To avoid receiving either of the error messages described above when you use the SetBackgroundPicture method in a Visual Basic macro, use any of the following methods:

Method 1: Activate the worksheet or chart that you want to add the graphic background to before the SetBackgroundPicture method command runs in the macro, as in the following examples:


             Worksheets(1).Select
             ActiveSheet.SetBackgroundPicture ("C:\Clipart\picture1.bmp") 
-or-

             Charts(1).Select
             ActiveSheet.SetBackgroundPicture ("C:\Clipart\picture2.bmp") 
Method 2: Apply the SetBackgroundPicture method to a Worksheet or Chart object directly as in the following examples:

             Worksheets(1).SetBackgroundPicture ("C:\Clipart\picture1.bmp") 
-or-

             Charts(1).SetBackgroundPicture ("C:\Clipart\picture2.bmp") 
Microsoft provides examples of Visual Basic procedures 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 Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.


REFERENCES

For more information about using the SetBackgroundPicture method in a Visual Basic macro in Microsoft Excel, click the Index tab in Microsoft Excel Help, and type the following text

setback
and then double-click the selected text to go to the "SetBackgroundPicture Method" topic.

Additional query words:

Keywords : kbcode kbprg
Version : WINDOWS:7.0
Platform : WINDOWS
Issue type :


Last Reviewed: October 25, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.