Adding a menu bar item in VBE

G

Gordon

I am trying to add a new (custom) popup control to the menu bar in
VBE....
(Office 98, OS 9.2)

The following code sample.........

Sub CreatePopup()
Dim cbpop As CommandBarControl
Dim cbctl As CommandBarControl
Dim cbsub As CommandBarControl

Application.VBE.CommandBars("Menu Bar").Reset

'Create a popup on main menu
Set cbpop = Application.VBE.CommandBars("Menu Bar"). _

Controls.Add(Type:=msoControlPopup, temporary:=True)
..
..
Generates the following error...........

Run-time error '-2147483640 (80000008)':

Method 'Add' of object 'CommandBarControls' failed

on the Set statement

If I select Help in the dialog box the following help topic appears...

Automation error (Error 440)
..
..
..

I have tried this a couple of different ways, all with more or less
the same result.

Also, if the control type to add is a button (type=1) things work
fine..

Looking for any suggestions!

Does anyone know, is this just not supported in this version?

Am I just missing some obvious step??

Have I completely cracked up???

Any and all help welcome


TIA

Gordon
 
J

JE McGimpsey

Does anyone know, is this just not supported in this version?

Am I just missing some obvious step??

Have I completely cracked up???

AFAIK, this is a long standing bug. I've had almost no success in
programming the VBE. While I can modify some toolbars (as you discovered
with buttons rather than popups), I've generally found that the VBE
becomes far less stable.
 
G

Gordon

Thanks for the post... and the warning!
I have had good success copying existing controls (of many types) to
a single toolbar (basically adding all the widgets I like to use to
one toolbar), but still have this as an open issue.

Thanks again,
Gordon
 
J

JE McGimpsey

Thanks for the post... and the warning!
I have had good success copying existing controls (of many types) to
a single toolbar (basically adding all the widgets I like to use to
one toolbar), but still have this as an open issue.

Since I've never discovered a way to successfully add a toolbar in the
VBE (I get automation errors), I delete the controls from the Standard
toolbar and repopulate it with my preferred selection:

Public Sub SetUpVBE()
Dim vCtrls As Variant
Dim ctrl As CommandBarControl
Dim begin As Boolean

vCtrls = Array(984, "b", 2559, 194, 188, "b", 228, 186, "b", _
2552, 192, "b", 14, 15, "b", 2554, 473, 222, _
2557, "b", 129, 128, "b", 106)
With Application.VBE
With .CommandBars("Standard")
.Visible = False
On Error Resume Next
For Each ctrl In .Controls
ctrl.Delete
Next ctrl
On Error GoTo 0
For i = 0 To UBound(vCtrls)
If vCtrls(i) = "b" Then
.Controls(1).BeginGroup = True
Else
.Controls.Add Id:=vCtrls(i), Before:=1
End If
Next i
.Protection = msoBarNoMove
.Visible = True
End With
End With
End Sub
 

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