Word AddIn using ComboBox in Standard Toolbar?

  • Thread starter Brian McCullough
  • Start date
B

Brian McCullough

Hello,

I have a really simple addin, created in VB6, that is just creating a
CommandBarComboBox control on the Standard Toolbar. I have code in place to
handle the change event for this control. I am designing to support Word XP
(Word 2002) and therefor primarily testing in XP (although I get similar
results in Word 2003).

Everytime I hit the change event (for example, by changing a value in the
combobox), I am getting the following error message and my control event
doesn't fire: "The macro cannot be found or has been disabled because of
your Macro security settings."

When I create this same add in for Excel, everything is working fine.

Any idea what is going on here? Is there something quirky with the
CommandBarComboBox change event in Word?



Here is some sample code:

Option Explicit

Private Const COMBO_TAG As String = "MyAddin"

Private WithEvents objWord As Word.Application
Private WithEvents objCombo As Office.CommandBarComboBox
Private objStandardToolbar As Office.CommandBar

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)

Set objWord = Application
Set objStandardToolbar = objWord.CommandBars("Standard")

RemoveCombo objStandardToolbar 'remove any previous instances of the
combobox
Set objCombo = CreateCombo(objStandardToolbar, AddInInst.ProgId) 'create
the combobox fresh
End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)

RemoveCombo objStandardToolbar

Set objStandardToolbar = Nothing
Set objCombo = Nothing
Set objWord = Nothing
End Sub

Private Sub objCombo_Change(ByVal Ctrl As Office.CommandBarComboBox)
MsgBox "Testing Combo Change" 'just display a msgbox
End Sub

Public Function CreateCombo(ByVal objCommandBar As Office.CommandBar, ByVal
strAddInProgID As String) As Office.CommandBarComboBox

Dim objCommandBarCombo As Office.CommandBarComboBox

'get a reference to the dropdown if it exists
Set objCommandBarCombo = objCommandBar.FindControl(Tag:=COMBO_TAG)

'If the button doesn't already exist, create it.
If objCommandBarCombo Is Nothing Then
Set objCommandBarCombo =
objCommandBar.Controls.Add(Type:=msoControlComboBox, Temporary:=True)
With objCommandBarCombo
.Style = msoComboLabel
.Tag = COMBO_TAG
.Caption = "Caption:"
.ToolTipText = "This is the tooltip"

.AddItem "Test1"
.AddItem "Test2"
.AddItem "Test3"

'determine what to do when the control events fire
.OnAction = "<!" & strAddInProgID & ">"

'position the button
.BeginGroup = True
End With
End If

'ensure the button and associated CommandBar are visible to the user
objCommandBarCombo.Visible = True
objCommandBar.Visible = True

'return the ComboBox
Set CreateCombo = objCommandBarCombo
End Function

Public Function RemoveCombo(ByVal objCommandBar As Office.CommandBar)
Dim objCombo As Office.CommandBarComboBox
Set objCombo = objCommandBar.FindControl(Tag:=COMBO_TAG)
If Not objCombo Is Nothing Then
objCombo.Delete False
End If
End Function
 
B

Brian McCullough

I tried moving the CommandBarComboBox into a custom CommandBar, and now the
Change event is firing, but before it fires, I get the "The macro cannot be
found or has been disabled because of your Macro security settings."
message still.

This looks like a message I would get if the OnAction property were not set
and it was trying to locate a macro by that name, but I am supplying the
name of my addin's progID.

Any ideas?

TIA!!!
-Brian
 
B

Brian McCullough

I should also note that my Macro Security Setting is currently specified at
Low and the "Trust all installed add-ins and templates" and "Trust access to
Visual Basic Project" options are both checked.

TIA...
 

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