Issue with userform pop-up menu

TheFrog

New Member
Joined
Aug 4, 2009
Messages
11
Hi Everyone,

Using Excel 2013 (32bit) to build an add-in for my workplace. Done lots of this sort of thing before but new to Excel 2013.

I have a userform with several controls on it, one of which is a TreeView. This TreeView control is used to display and interact with structured data from a backend database (in theory). I am trying to attach a pop up menu to the right click on this TreeView but with no success. The commandbar that is being used is defined correctly from what I can tell, but when the .ShowPopup method is called I receive an error: Run-Time error '-2147467259 (80004005)': Method 'ShowPopup' of object 'CommandBar' failed.

The code to generate the commandbar is is the forms initialise event, and the code that calls the ShowPopup method is in the TreeViews MouseUp event (there is no specific right-click event). See below:

Private Sub tvValues_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
If mFactor.ListIndex > -1 Then 'Must have something selected
If Button = acRightButton Then 'right button for menu

If mTV.SelectedItem Is Nothing Then
mGroup.ShowPopup
End If

End If
End If
End Sub



Private Sub UserForm_Initialize()

.....

'Code here to kill the bar off if it already exists...

Set mGroup = CommandBars.Add(Name:="tvValuesGroup", Position:=msoBarPopup, Temporary:=False)
With mGroup
.Controls.Add Type:=msoControlButton
.Controls(1).Caption = "New Group"
.Controls(1).OnAction = "addValueGroup"
.Controls.Add Type:=msoControlButton
.Controls(2).Caption = "Delete Group"
.Controls(2).OnAction = "removeValueGroup"
End With

.....
end sub

Looking in the Locals window I can see the various objects and their references are set correctly. mGroup for example is declared as a private variable (CommandBar) in the forms declarations section. I am not sure what is going wrong here, so any help or advice would be greatly appreciated.

Cheers and Thanks in Advance

The Frog
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Nevermind this one. Solved the issue using Windows API calls. Ni idea what VBA is doing but Commandbars popups dont work in 2013.
 
Upvote 0

Forum statistics

Threads
1,217,116
Messages
6,134,733
Members
449,886
Latest member
MD SHIBLI NOMAN NEWTON

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top