Hi everyone,

I have started a COM Addin project for Word and Excel. I am transferring a bunch of macros from templates and my personel.xls into this addin.

I have set up part of the custom Word toolbar and got that working using With Events. I am now working on modifying various shortcut menus to add in options like 'Insert Cross Reference', 'Insert Bookmark' and 'Paste Special'.

The way I had it in the old template was to use the ActionControl property after setting up the commandbarbutton on the shortcut menu. I have put the buttons on the respective shortcut menus OK, but the ActionControl is not working.

This is the OnConnection procedure:
[VBA]
Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set HostApp = Application

Call wdMenu.InitCmdBarCustomizations
End Sub
[/VBA]

The wdMenu.InitCmdBarCustomizations procedure sets the custom toolbar and then the following procedures for the short cut menus:

[VBA]
Option Explicit

Public HostApp As Object
Dim HostCmdBars As Office.CommandBars
Dim CBEvents As New CmdBarEvents

Private Sub MenItemsArrangement()
Dim cmdTextMenu As Office.CommandBarButton

On Error GoTo exitsubnow

Call GetCommandBars
Call wdMenu.ResetMenus

Set cmdTextMenu = HostCmdBars("text").Controls.Add(Type:=msoControlButton)
With cmdTextMenu
.Caption = "Insert Bookmark"
.FaceId = 1678
.Tag = "TextBookMark"
.BeginGroup = True
Set CBEvents.cmdTextMenu = cmdTextMenu
End With

exitsubnow:

End Sub

Sub GetCommandBars()
If HostApp.Name = "Outlook" Then
Set HostCmdBars = HostApp.ActiveExplorer.CommandBars
Else
Set HostCmdBars = HostApp.CommandBars
End If
End Sub

Sub ResetMenus()
HostCmdBars("text").Reset
End Sub

Sub DetermineMenu(ByRef sWhichDiag As String)
If sWhichDiag = "TextBookMark" Or sWhichDiag = "HelloEveryone" Then HostApp.Dialogs(wdDialogInsertBookmark).Show
End Sub
[/VBA]

Last but not least the class module CmdBarEvents has the following code:
[VBA]
Public WithEvents cmdTextMenu As Office.CommandBarButton

Private Sub cmdTextMenu_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Dim cmdBCtl As CommandBarControl

Set cmdBCtl = HostApp.CommandBars.ActionControl
Call wdMenu.DetermineMenu(cmdBCtl.Tag)
End Sub
[/VBA]

The trouble is that the code runs fine through [VBA]Set cmdBCtl = HostApp.CommandBars.ActionControl[/VBA] but doesn't set the cmdBCtl. When the next line is excuted, because there is nothing there the tag can't be read.

I hope this makes sense and someone can help.

Cheers,
Andrew