K
Kent Tessman
I'm having difficulty programmatically creating a toolbar with combobox
controls on it. It works fine on various combinations of Word and Windows,
but on OS X with either Word v.X or Word 2004, it crashes.
Here's a distillation of the code that causes the problem:
Public style_combo As CommandBarComboBox
Sub CreateMyFormattingToolbar()
Dim newbar As CommandBar
Set newbar = CommandBars.Add("My Formatting Toolbar")
newbar.Protection = msoBarNoCustomize
newbar.Position = msoBarTop
Set style_combo = newbar.Controls.Add(msoControlComboBox)
With style_combo
.Width = 120
.AddItem "Normal"
.AddItem "Title"
.OnAction = "StyleComboChanged"
End With
newbar.Visible = True
End Sub
When run from within the application, Word tells me:
"Method 'Width' of object 'CommandBarComboBox' failed"
and
"Method 'OnAction' of object 'CommandBarComboBox' failed" (if I comment out
the .Width line).
Run from the immediate window, the error is: "Automation Error"
Now, leaving aside the fact that Width and OnAction are properties, not
methods, the properties can be read, but not written. Without this working,
I'm at a loss as to how to create a combobox of a given width, or assign an
OnAction for it. Also, later, I need to check ListCount, and I get the same
crash. The AddItem method seems to work fine, however.
Again, all of this works fine in VBA/Word on Windows.
controls on it. It works fine on various combinations of Word and Windows,
but on OS X with either Word v.X or Word 2004, it crashes.
Here's a distillation of the code that causes the problem:
Public style_combo As CommandBarComboBox
Sub CreateMyFormattingToolbar()
Dim newbar As CommandBar
Set newbar = CommandBars.Add("My Formatting Toolbar")
newbar.Protection = msoBarNoCustomize
newbar.Position = msoBarTop
Set style_combo = newbar.Controls.Add(msoControlComboBox)
With style_combo
.Width = 120
.AddItem "Normal"
.AddItem "Title"
.OnAction = "StyleComboChanged"
End With
newbar.Visible = True
End Sub
When run from within the application, Word tells me:
"Method 'Width' of object 'CommandBarComboBox' failed"
and
"Method 'OnAction' of object 'CommandBarComboBox' failed" (if I comment out
the .Width line).
Run from the immediate window, the error is: "Automation Error"
Now, leaving aside the fact that Width and OnAction are properties, not
methods, the properties can be read, but not written. Without this working,
I'm at a loss as to how to create a combobox of a given width, or assign an
OnAction for it. Also, later, I need to check ListCount, and I get the same
crash. The AddItem method seems to work fine, however.
Again, all of this works fine in VBA/Word on Windows.