title: Automatically add a single menu item of an add-in in Excel
body: <p>I am using Microsoft Excel 2010 for Windows.</p>
  
  <p>I have already developed an add-in <code>addin.xlam</code>, which contains a sub <code>main</code>. <code>addin.xlam</code> is at the right place so that it is visible and selectable via the menu <code>Developer -&gt; Add-Ins</code>. When I open a normal workbook <code>test.xlsm</code>, and press <code>Alt + F11</code>, I can see the code of <code>addin.xlam</code> is loaded. </p>
  
  <p>My aim is to add a single menu item to the menu bar of Excel, to allow users to launch <code>main</code> of <code>add-in.xlam</code>. By following this <a href="http://www.ozgrid.com/VBA/excel-add-in-create.htm" rel="nofollow">link</a>, my code in <code>addin.xlam</code> is as follows:</p>
  
  <pre><code>Option Explicit
  Dim cControl As CommandBarButtonPrivate
  Sub Workbook_AddinInstall()
      On Error Resume Next 'Just in case
  
      'Delete any existing menu item that may have been left.
      Application.CommandBars("Worksheet Menu Bar").Controls("Super Code").Delete
  
      'Add the new menu item and Set a CommandBarButton Variable to it
      Set cControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
  
      'Work with the Variable
      With cControl
          .Caption = "Super Code"
          .Style = msoButtonCaption
          .OnAction = "main" 'Macro stored in a Standard Module
      End With
      On Error GoTo 0
  End Sub
  
  Private Sub Workbook_AddinUninstall()
      On Error Resume Next 'In case it has already gone.
      Application.CommandBars("Worksheet Menu Bar").Controls("Super Code").Delete
      On Error GoTo 0
  End Sub
  </code></pre>
  
  <p>This code is well placed in <code>ThisWorkbook</code> of <code>addin.xlam</code>, it is also visible in <code>test.xlsm</code>. <strong>But I can't see any change in the menu bar.</strong></p>
  
  <p>Does anyone know what happens?</p>