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

Last reviewed: September 3, 1997
Article 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 PgmHowTo
Version : 7.0
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.