Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created August 15, 2012 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dck-jp/3359830 to your computer and use it in GitHub Desktop.
Save dck-jp/3359830 to your computer and use it in GitHub Desktop.
Make AddIn with Toolbar @ VBA (Excel Only)
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
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