Programming VBE Add-ins -MZ-Tools P3
Programming VBE Add-ins -MZ-Tools P3
HOWTO: Adding buttons, commandbars and toolbars to the VBA editor of Office from an add-in with Visual Studio .NET.
Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Office 64-bit
Date: September 2012 Microsoft Office 32-bit
Introduction
This article explains how to add buttons, toolbars, commandbar popups, etc. to an add-in for the VBA editor of Office using Visual Studio .NET and
the .NET Framework.
More information
Create an add-in for the VBA editor of Microsoft Office as explained in the article HOWTO: Create an add-in for the VBA editor (32-bit or 64-bit) of
Office with Visual Studio .NET and use this code in the Connect.vb class.
Imports MyCompany.Interop
Imports MyCompany.Interop.Extensibility
Imports Microsoft.Office.Core
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Try
Case Extensibility.ext_ConnectMode.ext_cm_Startup
' OnStartupComplete will be called
Case Extensibility.ext_ConnectMode.ext_cm_AfterStartup
InitializeAddIn()
End Select
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Try
End Select
Catch e As System.Exception
System.Windows.Forms.MessageBox.Show(e.ToString)
End Try
End Sub
InitializeAddIn()
End Sub
End Sub
End Sub
commandBarControl = commandBar.Controls.Add(MsoControlType.msoControlButton)
commandBarButton = DirectCast(commandBarControl, CommandBarButton)
Return commandBarButton
End Function
Try
' ------------------------------------------------------------------------------------
' New toolbar
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
' New submenu under the "Tools" menu
' ------------------------------------------------------------------------------------
' ------------------------------------------------------------------------------------
' New main menu
' ------------------------------------------------------------------------------------
' Calculate the position of a new commandbar popup to the right of the "Tools" menu
toolsCommandBarControl = DirectCast(toolsCommandBar.Parent, CommandBarControl)
position = toolsCommandBarControl.Index + 1
Catch e As System.Exception
System.Windows.Forms.MessageBox.Show(e.ToString)
End Try
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
End Class
Related articles
HOWTO: Create an add-in for the VBA editor (32-bit or 64-bit) of Office with Visual Studio .NET
HOWTO: Create a button with a custom picture for the VBA editor of Office from an add-in with Visual Studio .NET.
HOWTO: Debug an add-in for the VBA editor (32-bit or 64-bit) of Office with Visual Studio .NET
HOWTO: Generate Interop assemblies to create an add-in for the VBA editor (32-bit or 64-bit) of Office with Visual Studio .NET
BUG: CommandBar.Name property localized in VBA editor of Office