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
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