Add Commandbar when Add-in is install

A

A.Q

Hi all,
I have this code, it works really well if I put it in workbook_open() event.
But I need the commandbar active when user install the add-in file. and
delete it when the add-in is removed
Thanks for your help

Private Sub Workbook_Open()

Dim oCb As CommandBar
Dim oCtl As CommandBarButton

On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("Import
Text").Delete
On Error GoTo 0
Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtl.Caption = "Import Text"
oCtl.Style = msoButtonCaption
oCtl.OnAction = "ImportText"
End With
End Sub
 
B

Bob Phillips

That should be okay as is as it will load when the workbook opens, that is
when it is installed and when Excel starts.

You should delete it when the addin closes

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar") _
.Controls("Import Text").Delete
On Error GoTo 0
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Commandbar on thisworkbook only 6
Check Existing Button 1
RunWhen error 4
Impossible? - Close code 1
Time close and save 0
Close help 2
Unable to disable macro 11
Help! Combine Macros 2

Top