lotrij
lotrij

Reputation: 101

Excel VSTO - Disable RibbonButton during Cell Edit

I am coding an Excel add in and would like my ribbon buttons to be disabled when the user is clicked into (editing) a cell. I see this happen with other ribbon buttons in Excel and in the TFS Excel add in so I'm hoping there's some way that other developers can accomplish it. Is there some way to determine/handle when an edit begins/ends (i.e. via double clicking/hitting Enter/hitting Escape)?

I was thinking I could manually enable/disable the buttons during these events. I was wondering if the technique described here http://www.codeproject.com/KB/office/Excel_Edit_Mode.aspx is the best way to detect if a cell is currently being edited?

Any guidance would be greatly appreciated.

Thanks

Upvotes: 2

Views: 2654

Answers (2)

Mike Cales
Mike Cales

Reputation: 101

Here is what I have done to accomplish the same goal as you.

I created a Timer set for 500ms In the event handler for the Timer, I perform the following check

if (Globals.ThisAddIn.Application.Ready)
{
     SetRibbonState()
}

Where SetRibbonState is something like this:

private void SetRibbonState()
{ 
     if (IsEditing())
     {
          buttonRefresh.Enabled = false;
     }
     else
     {
          buttonRefresh.Enabled = true;
     }
}

public static bool IsEditing()
{
    return !Globals.ThisAddIn.Application.CommandBars.GetEnabledMso(FileNewDefaultIdMso);
}

Upvotes: 2

Pascal
Pascal

Reputation: 742

Sorry for the late answer. I just came across your question.

I wanted the same behavior in my project and I succesfuly integrated this solution:

http://www.codeproject.com/KB/office/ExcelInEditMode.aspx

It was painless and worked very well. I just added the class in my project, created an instance of it and attached events to the EditModeOff and EditModeOn events.

Hope that helps (you or someone else)

Upvotes: 3

Related Questions