Hi,
I've been having a real tough time the following. I'm using Visual Studio 2010 Beta, developing a word template (.dotm) in Visual Basic.Net
I'm trying to add my own buttons on the text popup/context menu of word. However if I use the .OnAction property, I get an error msg in word stating the following:
The macro cannot be found or has been disabled because of your macro security settings
I'm assuming I get this error because it cannot locate the sub I'm trying to call (the name is correct and it resides in the same class).
I tried a different approach which is the WithEvents, however that associates the event with the LAST button I add to the menubar.
A third approach I tried was the AddHandler, that one fires once on then no more.
Here is the code I use:
For Each myItem In activeDoc.CommandBars If myItem.Type = Microsoft.Office.Core.MsoBarType.msoBarTypePopup And myItem.Name = officeMenuName Then shortMenu = Me.activeDoc.CommandBars(myItem.Index).Controls shortPopup = shortMenu.Add(Type:=Office.MsoControlType.msoControlPopup, Temporary:=True)
With shortPopup
.Caption = menuName
.Visible = True
End With
For i = LBound(menuItems) To UBound(menuItems)
shortItem = shortPopup.Controls.Add(Type:=Office.MsoControlType.msoControlButton, Temporary:=True)
AddHandler shortItem.Click, AddressOf shortMenuNu
With shortItem
.Caption = menuHeader(i)
.Visible = True
.Tag = menuItems(i)
.OnAction = "shortMenuItem_Click" 'where the name of the sub resides in the same class
'or AddHandler shortItem.Click, AddressOf shortMenuItem_Click
End With
shortItem = Nothing
Next
End If
Next
I would appreciate any input on this.
Any ideas?