Popup menu problem

M

Martin Stender

HI all - I grabbed the commandbar code below from the help-examples in
PPT, but it keeps failing with two different error messages: some of
the time, the 'showPopup' function fails with "invalid procedure call
or argument'), and sometime the menu will show once, and the next time
it is being called, it fails.

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift
As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
Set mybar = CommandBars.Add _
(Name:="Custom", Position:=msoBarPopup, Temporary:=False)
With mybar
.Controls.Add Type:=msoControlButton, Id:=3
.Controls.Add Type:=msoControlComboBox
End With
mybar.ShowPopup
End If
End Sub

Any ideas?

Best regards
Martin
 
M

Martin Stender

I forgot to add that it will be run from a form, not a slide ...

And I meant 'showPopup method', not function ... sorry :)

Martin
 
M

Martin Stender

Thank you Steve, you led me on the right track.

There were two problems:
1. my code would fail when trying to create a second commandbar with
the same name.
2. 'showpopup' requires that the main app is in focus.

This seems to work, although I do get an occasional error, but I think
that would never happen, when the code is run from an AddIn. (or?)

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then 'right-click

Application.Activate 'make sure PPT has our attention

Set cmMenu = CommandBars
For i = 1 To cmMenu.Count
If cmMenu(i).Name = "myPopUp" Then
cmMenu(i).Delete
End If
Next i

Dim myPopUp As Object
Set myPopUp = Application.CommandBars. _
Add(Name:="myPopUp", Position:=msoBarPopup,
Temporary:=True)
With myPopUp
.Controls.Add Type:=msoControlButton, Id:=3
'add more buttons here
End With
myPopUp.ShowPopup
End If

End Sub

Best regards
Martin
 
M

Martin Stender

Aaargh ... :)

To the above code, I've added one more button using this:

Set NewControl = .Controls.Add(Type:=msoControlButton)
With NewControl
.FaceId = 10
.Caption = "testing menu item"
.OnAction = "doStuff"
End With

There's of course a doStuff() function further down in the code, but it
never gets a call from the above .OnAction property.

Am I more than ordinarily stupid or does this require some special
woodoo?

Best regards
Martin
 
M

Martin Stender

Thank you Steve for taking the time.

I don't want to take up anymore of your time, but the doStuff sub still
don't get a call from the second menu item in the popup. I tried to
paste in the code from your site, and calling from a commandbutton like
this:

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift

As Integer, ByVal X As Single, ByVal Y As Single)
if Button = 2 then
CreateThePopup
DisplayMyPopup
end if
end sub

But never mind - I'll probably figure it out.
It's just weird it works in your end.

(I've also tried to make it into an add-in, just to try something, but
with the same result.)

Best regards
Martin
 

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

Similar Threads


Top