markus_zhang
New Member
- Joined
- Jan 11, 2018
- Messages
- 3
Hi Experts, I made an add-in and am trying to figure out how to remove the custom controls safely:
You can see that in AddinUninstall I'd like to confirm the existence of both controls before removing them. The FindControls method doesn't work as I cannot search the controls by name. I could search for ID, but again my Add-in will be used on may other computers so they may have different ID. So my question is, is there a way to check the existence of both Controls before removing them? Thanks!
Code:
Private Sub Workbook_AddinInstall()
Set cBackupRawControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
With cBackupRawControl
.Caption = "Backup Raw Data"
.Style = msoButtonCaption
.OnAction = "BackupRaw"
End With
Set cBacktestControl = Application.CommandBars("Worksheet Menu Bar").Controls.Add
With cBacktestControl
.Caption = "Back Test"
.Style = msoButtonCaption
.OnAction = "test"
End With
End Sub
Code:
Private Sub Workbook_AddinUninstall()
Dim cBRControl, cBTControl As CommandBarButton
'Set cBRControl = CommandBars.FindControls(ID:="Backup Raw Data")
'Set cBTControl = CommandBars.FindControls(ID:="Backup Test")
'If cBRControl Then
Application.CommandBars("Worksheet Menu Bar").Controls("Backup Raw Data").Delete
'End If
'If cBTControl Then
Application.CommandBars("Worksheet Menu Bar").Controls("Back Test").Delete
'End If
End Sub
You can see that in AddinUninstall I'd like to confirm the existence of both controls before removing them. The FindControls method doesn't work as I cannot search the controls by name. I could search for ID, but again my Add-in will be used on may other computers so they may have different ID. So my question is, is there a way to check the existence of both Controls before removing them? Thanks!