[FONT="]Hi all,
I'm attempting for the first time to create a custom toolbar that will be distributed as an add-in with set of macros to my colleagues.
I need it to be fool-proof and I have some doubts about it.
1. when browsing through different tutorials on this I noticed that in many codes toolbar is added on auto_open and it is added every time excel is opened. Is there any reason for this? It slows down opening of excel a little bit and I was wondering if there is any particular reason why it should be reinstalled every time.
2. I noticed that add-in could work in two ways:
- adding it through add-ins menu or
- just opening .xla file.
In first case command bar is added every time on excel open (which also causes it to be placed in default position every time) in the second case command bar is added only once and keeps all functionalities of "ordinary" command bar so remembers if it was on or of and where it was placed.
My question is there any harm in installing an add-in the second way? Could it cause some problems or difficulties besides obvious things like not being visible on add in list?
Here is my current code: Please feel free to critique any "bad practices" in it since I'm self and internet taught and always like to improve my bad habits.
I would appreciate any advice on this.
Thanks a lot![/FONT]
Sub Autpen()
Dim cb As CommandBar
Dim ctrl As CommandBarControl
Dim name As CommandBarButton
On Error Resume Next
Application.CommandBars("Benefits Survey Toolbar").Delete
On Error GoTo 0
Set cb = Application.CommandBars.Add(name:="Benefits Survey Toolbar")
With cb
.Visible = True
.Position = msoBarTop
Set name = .Controls.Add(Type:=msoControlButton)
With name
.Style = msoButtonCaption
.Caption = "Benefits Toolbar"
End With
Set ctrl = .Controls.Add(Type:=msoControlButton)
With ctrl
.BeginGroup = True
.Style = msoButtonIconAndCaption
.Caption = "Unprotect"
.FaceId = 225
.OnAction = "Unprotect.Unprotect"
.TooltipText = "Unprotect workbook and worksheets"
End With
Set ctrl = .Controls.Add(Type:=msoControlButton)
With ctrl
.Style = msoButtonIconAndCaption
.Caption = "Query"
.FaceId = 535
.OnAction = "'" & ThisWorkbook.name & "'!Benefits_CopyMacro.Benefits_CopyMacro"
.TooltipText = "Add questions to clarification"
End With
Set ctrl = .Controls.Add(Type:=msoControlButton)
With ctrl
.Style = msoButtonIcon
.FaceId = 441
.OnAction = "'" & ThisWorkbook.name & "'!Check_categories.Check_categories"
.TooltipText = "Check employee cat. consistency"
End With
End With
End Sub
I'm attempting for the first time to create a custom toolbar that will be distributed as an add-in with set of macros to my colleagues.
I need it to be fool-proof and I have some doubts about it.
1. when browsing through different tutorials on this I noticed that in many codes toolbar is added on auto_open and it is added every time excel is opened. Is there any reason for this? It slows down opening of excel a little bit and I was wondering if there is any particular reason why it should be reinstalled every time.
2. I noticed that add-in could work in two ways:
- adding it through add-ins menu or
- just opening .xla file.
In first case command bar is added every time on excel open (which also causes it to be placed in default position every time) in the second case command bar is added only once and keeps all functionalities of "ordinary" command bar so remembers if it was on or of and where it was placed.
My question is there any harm in installing an add-in the second way? Could it cause some problems or difficulties besides obvious things like not being visible on add in list?
Here is my current code: Please feel free to critique any "bad practices" in it since I'm self and internet taught and always like to improve my bad habits.
I would appreciate any advice on this.
Thanks a lot![/FONT]
Sub Autpen()
Dim cb As CommandBar
Dim ctrl As CommandBarControl
Dim name As CommandBarButton
On Error Resume Next
Application.CommandBars("Benefits Survey Toolbar").Delete
On Error GoTo 0
Set cb = Application.CommandBars.Add(name:="Benefits Survey Toolbar")
With cb
.Visible = True
.Position = msoBarTop
Set name = .Controls.Add(Type:=msoControlButton)
With name
.Style = msoButtonCaption
.Caption = "Benefits Toolbar"
End With
Set ctrl = .Controls.Add(Type:=msoControlButton)
With ctrl
.BeginGroup = True
.Style = msoButtonIconAndCaption
.Caption = "Unprotect"
.FaceId = 225
.OnAction = "Unprotect.Unprotect"
.TooltipText = "Unprotect workbook and worksheets"
End With
Set ctrl = .Controls.Add(Type:=msoControlButton)
With ctrl
.Style = msoButtonIconAndCaption
.Caption = "Query"
.FaceId = 535
.OnAction = "'" & ThisWorkbook.name & "'!Benefits_CopyMacro.Benefits_CopyMacro"
.TooltipText = "Add questions to clarification"
End With
Set ctrl = .Controls.Add(Type:=msoControlButton)
With ctrl
.Style = msoButtonIcon
.FaceId = 441
.OnAction = "'" & ThisWorkbook.name & "'!Check_categories.Check_categories"
.TooltipText = "Check employee cat. consistency"
End With
End With
End Sub