Checking if cell is in edit mode

Posted by ToM on 16. Juli 2009 under VSTO Excel |

We observed a very strange behaviour while updating cells when the user is currently editing a cell.

After doing some research on the net it seems that the only solution to determine if the cell is in edit mode is a very strange hack :-)

Obviously, the Application object has a method called GoTo(Range) to navigate to some areas. Somehow throws this method a special exception if it’s in edit mode. So the strange solution so far is to call Application.GoTo(”###”) and see what kind of exception it throws :)

protected bool isInEditMode()
{
   try
   {
      this.Application.Goto("###", false);
   }
   catch (Exception ex)
   {
      if (ex.Message.StartsWith("Reference is not valid"))
        return false;
      else
        return true;
   }
   return false;
}

Comments are closed.