XL: Sample Macro to Add Check Marks to Custom Menu Commands

Last reviewed: December 1, 1997
Article ID: Q111563
The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0
  • Microsoft Excel for the Macintosh, version 5.0
  • Microsoft Excel for Windows 95, version 7.0

SUMMARY

The following Microsoft Excel macro shows how to manage check marks in a custom menu command. The macro places a check mark next to the command when it is selected from the menu. When the command is selected again, the macro removes the check mark.

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 engineers 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/default.asp

Follow these steps to create and run the sample macro code:

  1. Insert a new module in a workbook.

  2. To add a command called "Database" below the Toolbars command on the View menu, choose the Menu Editor command from the Tools menu.

    For more information about using the Menu Editor, see pages 242-244 of the "Visual Basic User’s Guide."

  3. Select a portion of the worksheet that you want to be the database view and give it the assigned name "Database_View." Repeat this procedure for the worksheet view, and give that worksheet selection the defined name "Worksheet_View."

  4. Switch to the Visual Basic module, and enter the following code:

          Sub DatabaseView()
              With MenuBars(xlWorksheet).Menus("View").MenuItems("Database")
                  .Checked = Not .Checked 'toggles check mark on/off
                  If .Checked Then
                      'Switch to Database View
                      Application.Goto "Database_View", True
                  Else
                      'Switch to Worksheet View
                      Application.Goto "Worksheet_View", True
                  End If
              End With
          End Sub
    
    

  5. Using the Menu Editor, assign the DatabaseView macro to the Database command.

  6. Activate the worksheet.

  7. Choose Database from the View menu.

The macro will toggle the check mark on or off. When Database is selected, the macro scrolls the window to a cell range where a database is entered. If Database is not selected, the macro scrolls the window to a cell range where you can enter worksheet data.

REFERENCES

"Visual Basic User’s Guide," version 5.0, page 254


Additional query words: 5.00 howto
Keywords : kbcode kbprg PgmHowto
Version : WIDNOWS:5.0,7.0; MACINTOSH:5.0
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


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: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.