Created
August 15, 2012 12:44
-
-
Save dck-jp/3359830 to your computer and use it in GitHub Desktop.
Make AddIn with Toolbar @ VBA (Excel Only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Attribute VB_Name = "ModuleToolbar" | |
Option Explicit | |
Const toolbarName = "SampleToolbar" | |
Sub MakeToolBar() | |
Dim myBar As CommandBar | |
Dim myButton1 As CommandBarControl | |
Set myBar = Application.CommandBars.Add( _ | |
Name:=toolbarName, Position:=msoBarFloating) | |
myBar.Visible = True | |
'========================================================= | |
Set myButton1 = myBar.Controls.Add( _ | |
Type:=msoControlButton) | |
With myButton1 | |
.Style = msoButtonIconAndCaption | |
.OnAction = "sample" | |
.FaceId = 84 | |
.Caption = "sample" | |
End With | |
End Sub | |
Sub RemoveToolBar() | |
On Error Resume Next | |
Application.CommandBars(toolbarName).Delete | |
On Error GoTo 0 | |
End Sub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VERSION 1.0 CLASS | |
BEGIN | |
MultiUse = -1 'True | |
END | |
Attribute VB_Name = "ThisWorkbook" | |
Attribute VB_GlobalNameSpace = False | |
Attribute VB_Creatable = False | |
Attribute VB_PredeclaredId = True | |
Attribute VB_Exposed = True | |
Option Explicit | |
Private Sub Workbook_AddinInstall() | |
Call MakeToolBar | |
End Sub | |
Private Sub Workbook_AddinUninstall() | |
Call RemoveToolBar | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment