Run Macro when loading addin

M

Mary

I have created an AddIn that cointains custom functions and also a
code segment that creates a tool bar that cotains a macro that copies
the VBE module from the xla file to the active workbook.
The problem is that I dont know how to display the toolbar when the
add-in is loaded. In other words, I want the tool bar to be displayed
automatically once I have loaded the add-in. This the code I wrote.

This bugged me the entire day yesterday and I could not figure it out.

Mary


Sub CopyModule()
Dim Name22 As Variant
Dim test as String
Dim EconLibrary As String



Const tBarName As String = "Tool Bar name"
'Delete CommandBar if it exists
On Error Resume Next
CommandBars(tBarName).Delete
On Error GoTo 0

'create CommandBar
CommandBars.Add Name:=tBarName

'define an object variable to refer to the CommandBar
With CommandBars(tBarName)

'add button use 1 to specify a blank custom face
With .Controls.Add(ID:=1)
.OnAction = "Module1.CopyModule"
.Caption = "CopyModule"
.FaceId = 250

End With

'display the toolbar
.Visible = True
End With


Name22 = AddIns("EconLibrary").FullName

With Workbooks("EconLibrary.xla")
test = .Path & "\code.txt"
.VBProject.VBComponents("Module1").Export "test.bas"
End With

ActiveWorkbook.VBProject.VBComponents.Import "test.bas"



End Sub
 
D

Dave Peterson

You could call your macros from the auto_open() routine or from the
workbook_open() event:

In a general module:
sub auto_open()
call copyModule
end sub

Under the ThisWorkbook module:
Private Sub Workbook_Open()
call CopyModule
end sub

Use one or the other--not both.
 

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

Top