ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run Macro when loading addin (https://www.excelbanter.com/excel-programming/307863-run-macro-when-loading-addin.html)

Mary[_7_]

Run Macro when loading addin
 
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

E_R[_23_]

Run Macro when loading addin
 
You can put it in the Workbook_AddinInstall() even

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

Run Macro when loading addin
 
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.


Mary wrote:

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


--

Dave Peterson


Marylena Garcia

Run Macro when loading addin
 


Thanks a lot , problem solved.

Mary

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 03:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com