Addin Uninstalls itself everytime excel is closed

PennStateBrian

New Member
Joined
Aug 27, 2007
Messages
24
Hey everyone,

Have an issue that I think should be simple enough to fix. I have this addin (code below) that I want to be installed everytime I open excel, so that I have the menu item at my disposal. It seems however, whenever I close and reopen excel, the menu item is no longer there, but if I go to tools -> addins, it's still checked. So I have to uncheck it, then click ok, then go back to tools-> addins, reselect it, click ok. And THEN it shows up. Could I please get some guidance. Thanks.

Option Explicit
Dim objHelpMenuItem As CommandBarControl

Private Sub Workbook_AddinInstall()

Dim lngPos As Long
Dim objHelpMenu As CommandBar

Dim objExcelAbout As CommandBarControl

Set objHelpMenu = Application.CommandBars("Tools")

Set objExcelAbout = objHelpMenu.Controls("Macro")
If Not objExcelAbout Is Nothing Then
lngPos = objExcelAbout.Index
Else
lngPos = objHelpMenu.Controls.Count
End If

Set objHelpMenuItem = objHelpMenu.Controls.Add(msoControlButton, 1, , lngPos, True)

objHelpMenuItem.Caption = "Match and Sort..."
objHelpMenuItem.BeginGroup = True
objHelpMenuItem.OnAction = "sortData"


End Sub

Private Sub Workbook_AddinUninstall()

On Error Resume Next
objHelpMenuItem.Delete
On Error GoTo 0

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,971
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Rich (BB code):
Set objHelpMenuItem = objHelpMenu.Controls.Add(msoControlButton, 1, , lngPos, True)
The True argument makes the control temporary, which is not what you want. Change it to False.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,183
Messages
5,857,818
Members
431,900
Latest member
Paradime0346

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top