Event before menu displayed

D

David Thielen

Hello;

In my add-in, I need to enable/disable menu items based on the caret
position. Is there a better solution than the selection change event (which
is both very expensive and does not fire on all caret movements)?

All I need is an event that is fired just before any main menu is displayed
(like exists for the RMB pop-up menu).

thanks - dave
 
P

Peter Huang

Hi David,

To be more specified, can you tell us which office application do you mean,
word, excel or else ?
Also we can find all the event for the office applications in the vba help
file.
excel
C:\Program Files\Microsoft Office\OFFICE11\1033\VBAXL10.CHM
word
C:\Program Files\Microsoft Office\OFFICE11\1033\VBAWD10.CHM
and so on.

You may find all of them in the Content tab-->Events.

It seems that there is no event for special menu popup event.

Also is the menu you mean a context menu or the main menu(e.g. file menu)


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

This is a Word add-in.

On the main menu, I create a pop-up menu item (between Tools & Table) named
AutoTag.

Under the AutoTag menu I have the menu items "Insert Tag", "Edit Tag", and
"Delete Tag". When the AutoTag menu is displayed, I need to enable/disable
menu items depending on the location of the caret in the Word document.

If the caret is on a tag, I enable "Edit Tag" and "Delete tag" and disable
"Insert Tag". If the caret is not on a tag then I enable "Insert Tag" and
disable "Edit Tag" and "Delete tag".

The only solution I have come up with so far is to use the selection change
event which is bad both because it is trigger a LOT and because it is not
triggered for all caret movements (like typing characters).

Is there some kind of event that fires just before the pop-up menu is
displayed? There is one for the RMB menu.

thanks - dave
 
P

Peter Huang

Hi

I think you may try to use a context menu which will be invoke by right
click on the document.
We may handle the WindowBeforeRightClick event to build the context menu.

Commonly the menu in the file menu is for fixed usage, to display the menu
according to different scenario, I think we can use the context menu.



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hello;

I need to use the fixed menu. And if you look in the fixed menu under Edit
you will see the same thing - Copy and Cut are disabled unless text is
selected. So this is functionality that is needed in the fixed menu.

The question is, how can I enable/disable menu items there like Cut and Copy
are enabled/disabled?

thanks - dave
 
P

Peter Huang

Hi Dave,

For cut/copy menu, I think we can implement it in the WindowSelectionChange
event, if the sel.text is not nothing we can enable the menu,or we can
disable it.
Also, since many word implementations are based on internal implment, it
may be exposed as a method, property or event.

Dim WithEvents owd As Word.Application
Private Sub Command1_Click()
Set owd = New Application
owd.Visible = True
owd.Documents.Add
End Sub

Private Sub owd_WindowSelectionChange(ByVal Sel As Word.Selection)
Debug.Print Sel.Text
End Sub

From your description it seems that you did not wants to use the
WindowSelectionChange.
If you still have any concern,please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Selection change event is not good for two reasons:

1) It doesn't fire for all selection changes. If you type text, it does not
fire even though typing text changes the selection.
2) It does fire a LOT which makes it a problem to use as it slows down Word.

I am using it right now because it is the best solution I could find. But I
can see it slow down word when I move the cursor and I get complaints from
users because when they type text, my menu is then not enabled correctly.

There has to be a better way to do this - it is a pretty obvious need.

??? - thanks - dave
 
P

Peter Huang

Hi

I will research the issue and give your a reply ASAP.
Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi,

Now we are still researching the issue, and we will involve related
engineer on this issue. We will update you with new information ASAP.

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

Yan-Hong Huang[MSFT]

Hello Dave,

I am reviewing this issue thread. Are you still monitoring this issue? If
you are still monitoring this issue, please post another note to let me
know you are still there. Then I will investigate this for you.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hello;

Yes I am still monitoring. This is my #3 bug for my add-in.

thanks - dave
 
Y

Yan-Hong Huang[MSFT]

Hi Dave,

Thanks for the quick update. :) I am contacting the corresponding support
team now. We will be back here with more information as soon as possible.

If you have any concern on the reply, please feel free to post here and we
will follow up.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steve Danielson [MS]

Hi Dave,

My name is Steve Danielson from the Office Integration team and I will be
assisting you with this question. The functionaility that you desire
(something similar to a "BeforePopup" event that is fired before the
CommandBarPopup's menu is displayed) does not exist. There have been
similar requests for this functionality, and this product suggestion has
been submitted up to the Word/Office development team. The product team
does take these seriously, and if you wanted to submit this item (the more
submissions the higher the priority) you could do so here:

http://register.microsoft.com/mswish/suggestion.asp

You said that you were using Word, and that you had 3 menu items that you
wished to synchronize with the position of the caret in the document. You
said:
Under the AutoTag menu I have the menu items "Insert Tag", "Edit Tag", and
"Delete Tag". When the AutoTag menu is displayed, I need to enable/disable
menu items depending on the location of the caret in the Word document.
If the caret is on a tag, I enable "Edit Tag" and "Delete tag" and disable
"Insert Tag". If the caret is not on a tag then I enable "Insert Tag" and
disable "Edit Tag" and "Delete tag".

Are you working with an XML document with an attached schema with Word
2003? Word 2003 has a new event called XMLSelectionChange. Is this
appropriate for your use?

If not, then you are limited in your choices. One choice is to Optimize
your WindowSelectionChange the best that you can. You could back this up
with checking in your Click Event Handlers to be sure that the wrong
actions are not executed at the wrong time.

Another option would be to replace those three CommandBarButtons and
CommandBarPopup with a CommandBarButton that displays a modal dialog with
the choices. I realize that this would add extra steps and may reduce the
usability of the application, in the Click event for the button you would
be able to check the state and properly initialize the dialog.

For information and sample code for integrating Office with Visual Basic,
Visual C++, Internet Scripts, and other programming languages, please see
http://msdn.microsoft.com/library/techart/VSOfficeDev.htm. This site
contains the most up-to-date information for using developer tools for
Office integration and extensibility.

Thanks,
Steve Danielson, MCSD.NET
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Please visit the Microsoft Security & Privacy Center
(http://www.microsoft.com/security) for the latest news on security updates.
 
D

David Thielen

Yuck - not the answer I wanted. I'm using the SelectionChange event so I
guess I'll stick with that. (I am not using XML and an intermediate dialog
would be much worse.)

thanks - dave

ps - I am surprised that this functionality doesn't exist. You'ld think it
would be widely needed.
 
G

Guido Erlinger

dave wrote in news:[email protected]:
In my add-in, I need to enable/disable menu items based on the
caret position. Is there a better solution than the selection
change event (which is both very expensive and does not fire on
all caret movements)?

All I need is an event that is fired just before any main menu is
displayed (like exists for the RMB pop-up menu).

Yes that would be nice!

May be the following will help you.
I do this in an FrontPage Add-In.

In a class module I have the folowing code:
'-----------------------------
Dim WithEvents evtCBars As Office.CommandBars

Private Sub Class_Initialize()
Set oCBBtns = New clsCmdBarBtnCol
'... Changing the context menu
End Sub

Private Sub Class_Terminate()
Set evtCBars = Nothing
' ... Deleting the context menu
End Sub

Private Sub evtCBars_OnUpdate()
' Check the selection and update
' the state of my context items
End Sub
'-----------------------------

That was the only way to do this kind of
checking in FrontPage, because FP does not
have a selection change event. This works
for me ... but I do not have a time expensive
checking in evtCBars_OnUpdate()

cu, Guido
 
G

Guido Erlinger

'-----------------------------
Dim WithEvents evtCBars As Office.CommandBars

Private Sub Class_Initialize()
Set oCBBtns = New clsCmdBarBtnCol

I pasted the wrong code here: clsCmdBarBtnCol as
a collection of dynamicly created CommandBarButtons.
To activate the Events for evtCBars I have:

Set evtCBars = Application.CommandBars
'... Changing the context menu
End Sub

...

cu, Guido
 

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