Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pop-up menu 1

Status
Not open for further replies.

nesplb

Programmer
Jul 29, 2003
109
NO
Hi!
I wonder how to add a user defined menu to a pop-up menu..Can anyone help me?

To add a userdefined conrol I use this code:

Code:
Set menu1 = CommandBars.Add( _
    Name:="menu1", Position:=msoBarPopup, _
    Temporary:=True)
Set menuItem1 = menu1.Controls.Add
With menuItem1
    .FaceId = CommandBars("Userdefined menu1").Controls(1).ID
    .Caption = CommandBars("Userdefined menu1").Controls(1).Caption
    .OnAction = CommandBars("Userdefined menu1").Controls(1).OnAction
End With

How can I add a userdefined menu to "menu1"?
(See picture for description of a submenu on a popup-menu)

scr.jpg


Pål Nesteby

PDC-Tangen
Norway
 
Hi Pål,

You need to define your control as a popup and then it will have its own Controls collection which you can add to. Something like this ..

Code:
Set menu1 = CommandBars.Add( _
    Name:="menu1", Position:=msoBarPopup, _
    Temporary:=True)
Set menuItem1 = menu1.Controls.Add
Code:
(Type:=msoControlPopup)
Code:
With menuItem1
Code:
    .Caption = "This has a sub-menu"
    Set submenu1 = .Controls.Add
    With submenu1
Code:
        .FaceId = CommandBars("Userdefined menu1").Controls(1).ID
        .Caption = CommandBars("Userdefined menu1").Controls(1).Caption
        .OnAction = CommandBars("Userdefined menu1").Controls(1).OnAction
Code:
End With
Code:
End With

Enjoy,
Tony
 
Exactly what I needed!

Thanx!


Pål Nesteby

PDC-Tangen
Norway
 
Tony,
I have been trying to get pop-up menus to work on userforms for a while, I've posted a couple of time but had no responce, I tried your code but keep getting a "Invalid procedure call or argument (Error 5)" message, any idea where I am going wrong. I just pasted your code onto the "Userform1 code form" which contains a text box and set it to run on the mousedown event

like so
Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = xlSecondaryButton Then
Set menu1 = CommandBars.Add( _
    Name:="menu1", Position:=msoBarPopup, _
    Temporary:=True)
Set menuitem1 = menu1.Controls.Add
With menuitem1
    .FaceId = CommandBars("Userdefined menu1").Controls(1).Id
    .Caption = CommandBars("Userdefined menu1").Controls(1).Caption
    .OnAction = CommandBars("Userdefined menu1").Controls(1).OnAction
End With
End If
End Sub
[code]
any help would be apprecitated.

Mike
[pipe]
 
If you are using word98/2000 I think the problem is the name property in the add function.
In word XP this works fine, but in 98/2000 it doesn't work for some reason.

I just removed the name property and left it open and it worked fine!:)
like this:

Code:
Set menu1 = CommandBars.Add( _
    Position:=msoBarPopup, _
    Temporary:=True)

Pål Nesteby

PDC-Tangen
Norway
 
As we are talking about pop-up menus....

Does anyone know how to get a line in in the pop-up menu?

The original menu (This is how I want the pop-up to look like):

menu1.jpg



And this is how the pop up menu looks like:
(I want to insert two thin grey lines as shown above)
The picture property doesn't work in word2000 as far as I know..
menu2.jpg


thanx

Pål Nesteby

PDC-Tangen
Norway
 
Some time since I did this, but, the menuitem has a begingroup property, which by default is set to False. Set this to true, and you'll get a grey line above this item.

Ie when you set the OnAction, Caption... properties, also do
.BeginGroup=True
for those items you need grouping before.

Roy-Vidar, Also Norway;-)
 
Thank you Roy-Vidar!
-Nice to see some Norwegians here!



Pål Nesteby

PDC-Tangen
Norway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top