event with commandbar button right-click?

R

RB Smissaert

Would it somehow be possible to trigger an event on right-clicking a
commandbar button?

These buttons are created like this:

Public cb2 As CommandBar

Set cb2 = CommandBars.Add("MyOptionsPopUp", _
msoBarPopup, _
MenuBar:=False, _
temporary:=True)

With cb2
Set FileControl = .Controls.Add(Type:=msoControlPopup)
With FileControl
.Caption = "File"
With .Controls.Add(Type:=msoControlButton)
.Caption = "Open report (F3 OR O from the treeview)"
.OnAction = "OpenReport"
.FaceId = 23
End With

etc.


The purpose is to trigger context sensitive help on the menu.


RBS
 
G

Guest

Hi,

Not so sure about right-click, but Office CommandBar controls (2k3) do have
..HelpFile and .HelpContextId properties that can be set. Look these up in the
Excel VBA help - where it also says that "Help topics respond to Shift+F1".

So maybe something like ...

With .Controls.Add(Type:=msoControlButton)
.Caption = "Open report (F3 OR O from the treeview)"
.OnAction = "OpenReport"
.FaceId = 23
.HelpFile = "C:\...\myHelpFile.hlp" ' Full path to your compiled help
file.
.HelpContextID = 69
' The topic ID number that has been correctly mapped to a topic in your
compiled help file.
End With

Don't know if this also works with HtmlHelp compiled help files (*.chm) or
not - I'm having my own set of problems with text-popup context-sensitive
help (see my other post) from HtmlHelp.

Trust this helps and let me know how you get on.

Cheers, Sean.
 
R

RB Smissaert

OK, but what I want to do is somehow point to the menu item (not the routine
that is pointed at by the menu item) and then get the help related to that
menu
item. Not sure how your .HelpContextID = 69 in the menu code would fit in
with
this.
One problem is that I can't show a WhatsthisHelp button in my userform as
the title bar has minimize and maximize buttons added by the Windows API.

What I could do, althought it is not that slick is have a checkbox on the
form and
then when this is ticked and you click (left-click) the menu item the help
will popup
and not the normal menu routine.

I will report back when I have a solution for this and I would be interested
if you
have some new ideas.

RBS
 
G

Guest

Hi,

Maybe I've got it all wrong. The assumption on my part (that may indeed be
incorrect) is that you want to attach some help to an Office CommandBar
control. *One* way to achieve this is detailed in my earlier post (and
further in the Excel VBA help for the .HelpFile and .HelpContextID properties
- look them up in the VBA Object Browser). This method assumes that the help
that you want to provide your users is a topic in a compiled help file that
has previously been created (e.g. by you).

..HelpContextID is a long integer that simply represents the relevant help
topic that you want displayed when the user presses Shift+F1 when the
relevant Office CommandBar control has the 'focus'. You 'map' (or associate)
the .HelpContextID to actual help topics in your help file creator (WinHelp
or HtmlHelp) and then compile the help file (into a *.hlp or *.chm file
respectively). "What's This" type help pertains to user forms, which I am
again assuming is not relevant to your case. UserForm controls are a
completely separate matter.

AFAIK, I haven't come across an easy way of intercepting the right
mouse-click event of an Office CommandBar control object. (In fact, and again
AFAIK, Office CommandBar controls do not have any exposable events available).

I hope this helps. If I am misunderstanding it badly, then there may be
others in the community that know more or have grasped the nub of your
problem better than I have.

Good Luck. Cheers, Sean.
 
R

RB Smissaert

Ah, I see, it works with F1.
My help is a bit different in that is an online help.
I can bring the relevant bit of the help up with a Sub like this:

Sub LoadContextHelp(lHelpID As Long)

If Application.Workbooks.count = 0 Then
Application.Workbooks.Add
End If

ActiveWorkbook.FollowHyperlink _
"http://www.xxxxx.whcsh_home.htm#id=" & lHelpID

End Sub

Where lHelpID is the HelpContextID of the control. For labels it will the be
tag as the HelpContextID doesn't work for me
with labels.
So, maybe adding the HelpContextID to the commandbar controls may somehow do
the trick via the F1 key, but not sure it can
work with an on-line help on a server.
Will give it a try.


RBS
 
G

Guest

OK, I understand a bit better now.

I think there is some confusion here around whether you are trying to
program an Office CommandBar control (e.g. on a toolbar or menu) or an
MSForms control (on a userform). They are different objects with different
properties, methods etc. and you have to work with them in different ways.

Left mouse-clicking an Office CommandBar control executes the subroutine
defined by its .OnAction property. MSForms UserForm controls (ListBox,
OptionButton etc.) have 'Events' that can be intercepted (e.g. 'Click').
Another of these events is MouseUp and for a UserForm control (a
CommandButton named 'CommandButton1' in the example below) you could use
something like the following to capture the right mouse-click event. (This
code goes in the form's code module, not a standard module).

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 mouse button.
' Your code here to call your help or whatever you need to do.
End If
End Sub

One last tip that may be useful to you. Office CommandBar controls also have
a .ToolTipText property. If your help message is short, you can set this
..ToolTipText property and then when a user 'hovers' the mouse over the item,
the .ToolTipText property is displayed in a popup. MSForms UserForm controls
have a .ControlTipText property that functions in the same way.

Trust all this helps. Let me know how you get on.

Cheers, Sean.
 
R

RB Smissaert

This is a big menu (with submenus) that pops up when a button on a userform
is clicked. The code that createst the menu was in the first posting.
These menu items have no mousedown event etc.

Maybe the easiest way is to do it like this:
The button that has to be pressed to make the menu appear could be
right-clicked and that changes the caption of the button from Options to
OptionsH and vice versa. When the caption is OptionsH the help will be
produced rather than
the routine the menu command button is pointing to.

It is slightly more user action, but still acceptable.
Unless somebody can tell me a better way ...

RBS
 

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