Event when Excel goes in/out of edit mode

J

Jialiang Ge [MSFT]

Hello Dave,

It has been confirmed that Excel does not expose an event when cells go
in/out of edit mode. But if you are using the method
http://www.codeproject.com/KB/office/Excel_Edit_Mode.aspx, a possible
workaround is to register the CommandBars.OnUpdate event, which will be
fired when CommandBar's status is changed. Each time we enter the edit
mode, the CommandBars's status is changed because some built-in
commandBarbuttons will disabled. The event will also be fired when we quit
the edit mode. Therefore, we could register the event with the code:

applicationObject.CommandBars.OnUpdate += new
Microsoft.Office.Core._CommandBarsEvents_OnUpdateEventHandler(CommandBars_On
Update);

and in the CommandBars_OnUpdate method, we could check if a certain
built-in CommandBarButton is disabled as the article
http://www.codeproject.com/KB/office/Excel_Edit_Mode.aspx says. If true, we
add a flag 'edit-mode' to store the state. When we quit the edit mode, we
check if the edit-mode equals true, and if the certain CommandBarButton is
enabled. If both return true, we assign false to the 'edit-mode' flag, and
tell the application that we are now quitting the edit mode.

Hope it helps.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

We have a problem - the event stops firing after awhile. I only have 1 copy
of Excel running and just one workbook. And I never leave the first
worksheet. But after about 30 seconds it stops firing.

Do I need to keep a global variable of the CommandBars? I do have a global
variable of the ApplicationObject.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Jialiang Ge [MSFT]

Hello Dave,

I did a test again in my side, but it seems that the event always fired
when the commandbars changed. I called
applicationObject.CommandBars.OnUpdate += new
Microsoft.Office.Core._CommandBarsEvents_OnUpdateEventHandler(CommandBars_On
Update);
in the OnConnection function. And the CommandBars_OnUpdate event hanlder is
simply like:

void CommandBars_OnUpdate()
{
MessageBox.Show("test");
}

Would you let me know how did you add the event handler? Is it possible
that the event has actually been fired, but the code in the event handler
does not follow the logic correctly, and failed to disable/enable the
add-in CommandBarButton? To test if the event is fired, you may add the
line MessageBox.Show("test"); at the very beginning of the event handler,
and see if the messge box is popped out.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

I tested again and the code you listed stops working after about 30 seconds.
But the following works:

private CommandBars mainMenu;
public override void OnStartupComplete()
{
base.OnStartupComplete();

mainMenu = NativeApplication.CommandBars;
mainMenu.OnUpdate += CommandBars_OnUpdate;
}

private void CommandBars_OnUpdate()
{
menu.Update();
}

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

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