title: VBA remove custom add in tab
body: <p>I found code from Stack Overflow which allowed me to add a custom tab by uploading the xlam file as an add-in (see code below). Unfortunately, the <code>Deactivate</code> section doesn't remove the custom tab from the Ribbon when I de-select the add-in from the Developers tab. </p>
  
  <p>I have seen examples where you can hide tabs through <code>GetVisible</code>, but I don't know how to incorporate it with the code below. And I haven't found any simpler action which identifies and removes the tab when de-selecting the add-in from the developer tab.</p>
  
  <pre><code>Private Sub Workbook_Open()
  
      Dim hFile As Long
      Dim path As String, fileName As String, ribbonXML As String, user As String
  
      hFile = FreeFile
      user = Environ("Username")
      path = "C:\Users\" &amp; user &amp; "\AppData\Local\Microsoft\Office\"
      fileName = "Excel.officeUI"
  
      ribbonXML = "&lt;mso:customUI       xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "  &lt;mso:ribbon&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "    &lt;mso:qat/&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "    &lt;mso:tabs&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "      &lt;mso:tab id='reportTab' label='Misc' insertBeforeQ='mso:TabFormat'&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "        &lt;mso:group id='reportGroup' label='Source Sheet' autoScale='true'&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "          &lt;mso:button id='runReport' label='Create Sheet' " &amp; vbNewLine
      ribbonXML = ribbonXML + "imageMso='AppointmentColor3'      onAction='CreateSheet'/&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "        &lt;/mso:group&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "        &lt;mso:group id='Group2' label='Formatting' autoScale='true'&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "          &lt;mso:button id='FormatButtons' label='Format Selection' " &amp; vbNewLine
      ribbonXML = ribbonXML + "imageMso='AppointmentColor3'      onAction='Test2'/&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "        &lt;/mso:group&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "      &lt;/mso:tab&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "    &lt;/mso:tabs&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "  &lt;/mso:ribbon&gt;" &amp; vbNewLine
      ribbonXML = ribbonXML + "&lt;/mso:customUI&gt;"
  
      ribbonXML = Replace(ribbonXML, """", "")
  
      Open path &amp; fileName For Output Access Write As hFile
      Print #hFile, ribbonXML
      Close hFile
  
  End Sub
  </code></pre>
  
  
  
  <pre><code>Private Sub Workbook_Deactivate()
  
      Dim hFile As Long
      Dim path As String, fileName As String, ribbonXML As String, user As String
  
      hFile = FreeFile
      user = Environ("Username")
      path = "C:\Users\" &amp; user &amp; "\AppData\Local\Microsoft\Office\"
      fileName = "Excel.officeUI"
  
      ribbonXML = "&lt;mso:customUI           xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui""&gt;" &amp; _
      "&lt;mso:ribbon&gt;&lt;/mso:ribbon&gt;&lt;/mso:customUI&gt;"
  
      Open path &amp; fileName For Output Access Write As hFile
      Print #hFile, ribbonXML
      Close hFile
  
  End Sub
  </code></pre>