O
OughtFour
I use the following routine to test each menu and toobar control, visible or
not:
Private Sub EnableMenuette(vControl As Variant, vName As String, IsADoc As
Boolean)
'Does heavy lifting for EnableMenuItem, recursively
Dim thang As Variant
For Each thang In vControl.Controls
If thang.Caption = vName Then
thang.Enabled = IsADoc
ElseIf thang.Type = msoControlPopup Then
'i.e., if thang is itself a menu,
EnableMenuette thang, vName, IsADoc
End If
Next thang
End Sub
It uses recursion to get at sub menus. It is called by a routine that
includes these lines
For Each menu In CommandBars
EnableMenuette menu, vName, IsADoc
Next menu
(What I am doing is checking for the presence of particular toolbar button
and menu item vName, which may be anywhere and in more than one place due to
user customization.)
This works fine in Word 97 for Windows, but fails in Word X. The error
message says
Run-time error '-2147483640 (800000080)':
Method 'Controls' of object 'CommandBarPopup' failed.
Execution halts at
For Each thang In vControl.Controls
It seems to be hung up when it reaches the Toolbars submenu on the View
menu.
I surmise that the problem lies in applying the Controls method.
I feel baffled by this. I thought I understood the CommandBars collection
well enought to do this but apparently I do not.
But, why does it work in Word 97?
Grateful for any help at all, thanks.
not:
Private Sub EnableMenuette(vControl As Variant, vName As String, IsADoc As
Boolean)
'Does heavy lifting for EnableMenuItem, recursively
Dim thang As Variant
For Each thang In vControl.Controls
If thang.Caption = vName Then
thang.Enabled = IsADoc
ElseIf thang.Type = msoControlPopup Then
'i.e., if thang is itself a menu,
EnableMenuette thang, vName, IsADoc
End If
Next thang
End Sub
It uses recursion to get at sub menus. It is called by a routine that
includes these lines
For Each menu In CommandBars
EnableMenuette menu, vName, IsADoc
Next menu
(What I am doing is checking for the presence of particular toolbar button
and menu item vName, which may be anywhere and in more than one place due to
user customization.)
This works fine in Word 97 for Windows, but fails in Word X. The error
message says
Run-time error '-2147483640 (800000080)':
Method 'Controls' of object 'CommandBarPopup' failed.
Execution halts at
For Each thang In vControl.Controls
It seems to be hung up when it reaches the Toolbars submenu on the View
menu.
I surmise that the problem lies in applying the Controls method.
I feel baffled by this. I thought I understood the CommandBars collection
well enought to do this but apparently I do not.
But, why does it work in Word 97?
Grateful for any help at all, thanks.