Microsoft KB Archive/111563: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 58: Line 58:
<ol>
<ol>
<li>Insert a new module in a workbook.</li>
<li>Insert a new module in a workbook.</li>
<li>To add a command called &quot;Database&quot; below the Toolbars command on the View menu, choose the Menu Editor command from the Tools menu.<br />
<li>To add a command called "Database" below the Toolbars command on the View menu, choose the Menu Editor command from the Tools menu.<br />
<br />
<br />
For more information about using the Menu Editor, see pages 242-244 of the &quot;Visual Basic User's Guide.&quot;</li>
For more information about using the Menu Editor, see pages 242-244 of the "Visual Basic User's Guide."</li>
<li>Select a portion of the worksheet that you want to be the database view and give it the assigned name &quot;Database_View.&quot; Repeat this procedure for the worksheet view, and give that worksheet selection the defined name &quot;Worksheet_View.&quot;</li>
<li>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."</li>
<li><p>Switch to the Visual Basic module, and enter the following code:</p>
<li><p>Switch to the Visual Basic module, and enter the following code:</p>
<pre class="codesample">      Sub DatabaseView()
<pre class="codesample">      Sub DatabaseView()
           With MenuBars(xlWorksheet).Menus(&quot;View&quot;).MenuItems(&quot;Database&quot;)
           With MenuBars(xlWorksheet).Menus("View").MenuItems("Database")
               .Checked = Not .Checked 'toggles check mark on/off
               .Checked = Not .Checked 'toggles check mark on/off
               If .Checked Then
               If .Checked Then
                   'Switch to Database View
                   'Switch to Database View
                   Application.Goto &quot;Database_View&quot;, True
                   Application.Goto "Database_View", True
               Else
               Else
                   'Switch to Worksheet View
                   'Switch to Worksheet View
                   Application.Goto &quot;Worksheet_View&quot;, True
                   Application.Goto "Worksheet_View", True
               End If
               End If
           End With
           End With
Line 87: Line 87:
== REFERENCES ==
== REFERENCES ==


&quot;Visual Basic User's Guide,&quot; version 5.0, page 254
"Visual Basic User's Guide," version 5.0, page 254


</div>
</div>

Latest revision as of 11:09, 20 July 2020

Knowledge Base


Sample Macro to Add Check Marks to Custom Menu Commands

Article ID: 111563

Article Last Modified on 6/11/2007



APPLIES TO

  • Microsoft Excel 95 Standard Edition
  • Microsoft Excel 5.0 Standard Edition
  • Microsoft Excel 5.0 for Macintosh



This article was previously published under Q111563

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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. 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: howto XL

Keywords: kbcode kbhowto kbprogramming KB111563