Newbie: OL XP Adding button to Menu Bar and drop-down menu...

A

Allan Rees-Bevan

Hi all, trying to programmatically, on Outlook XP startup, add extra menu to
Menu Bar with drop down, and assign macro to button - this is what I have,
cribbed from a Word XP template I had a hand in, but nothing happens, Allan:
================================
Public Sub AutoExec()

AddMasonsMenu

End Sub
================================
Public Function AddMasonsMenu() As Boolean
On Error Resume Next
Dim objCBar As CommandBar
Dim objCBCtrl As CommandBarControl
Dim objInsMenu As CommandBar
Dim objCVMenu As CommandBar
Dim objTBMenu As CommandBar
Dim objTBOMenu As CommandBar
Dim strCaption As String
Dim strTag As String
Dim strCBName As String
Dim strOnAction As String
Dim strTip As String
Dim intType As Integer
Dim intControlsCount As Integer
Dim blnNeedSave As Boolean

If CommandBars("Menu Bar").FindControl(msoControlPopup, , "Masons",
True) Is Nothing Then
strCaption = "&Masons"
strTag = "Masons"
Set objCBar = AddMenu(strCaption, strTag)
strCBName = "Masons"
blnNeedSave = True
End If

Set objCBar = CommandBars("Menu Bar").Controls("Masons").CommandBar

Set objCBCtrl = AddCBarControl(objCBar, "&Conflict Checking",
msoControlButton, _
"modConflictCheck.CallCompForm", "CallCompForm", "")

End Function
================================
Public Sub CallCompForm()

frmConflictCheck.Show

End Sub
================================
 
A

Allan Rees-Bevan

OK, figured out the code for the pop-up menu, now, how do I call it on
Outlook startup? FYI, code included below...
======================
Sub AddMasonsMenu()
Dim objOL As Outlook.Application
Dim colCB As Office.CommandBars
Dim objCB As Office.CommandBar
Dim objCBMenu As Office.CommandBarPopup
Dim objCBMenuCB As Office.CommandBar
Dim objCBB As Office.CommandBarButton

Set objOL = CreateObject("Outlook.Application")
Set colCB = objOL.ActiveExplorer.CommandBars
Set objCB = colCB.Item("Menu Bar")

If objCB.Controls.Item(7).Caption = "Ma&sons" Then

objCB.Controls.Item(7).Delete

Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup, _
Before:=7, Temporary:=True)
With objCBMenu
.Caption = "Ma&sons"
Set objCBMenuCB = .CommandBar
Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, _
ID:=1744, Temporary:=True)
objCBB.Caption = "Conflict Check"
objCBB.OnAction = "CallCompForm"
End With

Set objOL = Nothing
Set colCB = Nothing
Set objCB = Nothing
Set objCBMenu = Nothing
Set objCBMenuCB = Nothing
Set objCBB = Nothing

End If

End Sub
======================
 
S

Sue Mosher [MVP-Outlook]

Put any code that you want to run at startup in the Application_StartUp
event handler in the built-in ThisOutlookSession module.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

Allan Rees-Bevan

That's brilliant - thank you (and thank you for the menu-building code too!)
Allan
 
A

Allan Rees-Bevan

Me again - apparently there's an issue with using the VBAProject.OTM in OL 2000 and OL XP? Once sent to users, thay need to go into VBA and then restart Outlook to get the macros to work!! And we can't do this with 700 users. So, my further question is - do I need to do this as a com addin? And if so, do I...
a.. I use the IDTExtensibility2 interface
b.. Add the "startup" code to the OnStartupComplete event
c.. What do I put into the InitHandler sub then? Should I be putting the "startup" code in here instead? (by "startup" I mean call the AddMasonsMenu sub... And where do I put the InitHandler sub? Can I put it in a module, or does it need to be in a class module?
I apologise for all the questions, but this is a time-sensitive project and I'm floundering!!

Allan
 
S

Sue Mosher [MVP-Outlook]

Yes, VBA projects are for your personal use. For enterprise use, you should
build a COM addin. Go to http://www.microeye.com/ and get the Items Command
Bar or the other template from the Resources section. These will show you
the correct structure for a COM addin that will gracefully close when
Outlook closes.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Me again - apparently there's an issue with using the VBAProject.OTM in OL
2000 and OL XP? Once sent to users, thay need to go into VBA and then
restart Outlook to get the macros to work!! And we can't do this with 700
users. So, my further question is - do I need to do this as a com addin? And
if so, do I...
a.. I use the IDTExtensibility2 interface
b.. Add the "startup" code to the OnStartupComplete event
c.. What do I put into the InitHandler sub then? Should I be putting the
"startup" code in here instead? (by "startup" I mean call the AddMasonsMenu
sub... And where do I put the InitHandler sub? Can I put it in a module, or
does it need to be in a class module?
I apologise for all the questions, but this is a time-sensitive project and
I'm floundering!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top