XL: Hiding Button Objects with Visual Basic for Applications

ID: Q111392

The information in this article applies to:

SUMMARY

This article describes two methods for preventing buttons from printing when you print the worksheet that contains the buttons.

NOTE: In Microsoft Excel 97 and Microsoft Excel 98, buttons within a worksheet are not printed by default.

MORE INFORMATION

Microsoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/

To print a worksheet without printing button objects, follow the appropriate procedure below.

If the Worksheet Does Not Contain Other Graphic Objects

1. On the Edit menu, click Go To.

2. Click Special to open the Go To Special dialog box.

3. In the Go To Special dialog box, click the Objects option to select all

   objects on the worksheet. Click OK.

4. On the Format menu, click Object, and then click the Properties tab.

5. On the Properties tab, clear the Print Object check box. Click OK

   to accept the change.

If the Worksheet Contains Other Graphic Objects In Addition To Buttons

1. On the Insert menu, point to Macro, and then click Module.

   In Microsoft Excel 97 or Microsoft Excel 98, click the Tools menu, point
   to Macro, and then click Visual Basic Editor. On the Insert menu, click 
   Module.

2. In the new module, type the following Visual Basic code:

      Sub Print_No_Buttons()
          ActiveSheet.Buttons.Select
      End Sub

3. Return to the sheet that contains the buttons. Click Macro on the Tools
   menu. (In Microsoft Excel 97 or Microsoft Excel 98, click the Tools
   menu, point to Macro, and then click Macros.)

4. In the Macro dialog box, select the Print_No_Buttons macro, and click
   Run.

   All of the buttons on the active worksheet are now selected.

5. Click Object on the Format menu and click the Properties tab.

6. Clear the "Print Object" check box, and then click OK.

   When you print out this worksheet, the buttons will not be printed.

NOTE: When you choose the Objects option in the Go To Special dialog box, all objects are selected. This means that if the Print Object check box is cleared, none of the graphic objects will be printed.

Additional query words: 5.00 5.00a 5.00c 7.00 7.00a 8.00 XL97 XL98 VBAEq

Keywords          : kbprg kbdta kbdtacode PgmHowto KbVBA 
Version           : WINDOWS:5.0,7.0,97; MACINTOSH:5.0,98
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: May 17, 1999