How to tell if Excel Application is in cell-edit mode?

后端 未结 3 1431
悲哀的现实
悲哀的现实 2020-12-18 12:35

I\'m writing an Excel Addin using COM Interop from .net. I have a command that pops up a dialog, and from the dialog I do some work like collecting data from the used range

3条回答
  •  伪装坚强ぢ
    2020-12-18 13:25

    You didn't mention which language you're using. SZL's function is written in VB. Since I'm using C# I had to convert it. Worked great. Here is the equivalent C# code.

        bool IsInEditMode(ref Microsoft.Office.Interop.Excel.Application exapp)
        {
            if (exapp.Interactive == false)
            {
                return false;
            }
            else
            {
                try
                {
                    exapp.Interactive = false;
                    exapp.Interactive = true;
                    return false;
                }
    
                catch
                {
                    return true;
                }
            }
    
        }
    

提交回复
热议问题