PDA

View Full Version : Dynamically add Toolbar with Buttons



Jeevie
02-12-2011, 08:05 AM
Hi

Can someone share code sample on how to check for a Toolbar and accordingly add a custom toolbar with buttons.

Thanks in advance

Zack Barresse
02-20-2011, 01:35 PM
Hi there,

You might be able to use something like this, although I'm not sure what version you're working with...

Private Sub Application_Startup()
Dim olApp As Application, NS As NameSpace, olFld As Folder
Dim cbMenu As CommandBar, cmbNew As CommandBarButton
On Error Resume Next
Set olApp = Outlook.Application
Set NS = olApp.GetNamespace("MAPI")
Set olFld = NS.GetDefaultFolder(olFolderInbox)
olApp.ActiveExplorer.CurrentFolder = olFld
Set cbMenu = ActiveExplorer.CommandBars("Menu Bar")
'Menu Bar
'Standard
'Advanced
'Web
On Error Resume Next
Set cmbNew = cbMenu.Controls("Caption").Delete
On Error Resume Next
Set cmbNew = cbMenu.Controls.Add(msoControlButton)
With cmbNew
.Caption = "Caption"
.OnAction = "macroName"
.TooltipText = "toolTip"
.FaceId = "FaceId"
.Style = msoButtonIconAndCaption
.BeginGroup = True
End With
End Sub

HTH