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

六眼飞鱼酱① 提交于 2019-11-29 08:45:11

There is an Application.Ready property that is supposed to give you this information but in practice it doesn't work reliably. See here for a hackaround.

You might also want to look at setting Application.Interactive=false while your .net code is doing its stuff.

Try this function:

    Function IsInEditMode(ByRef exapp As Excel.Application) As Boolean
        If exapp.Interactive = False Then
            Return False
        Else
            Try
                exapp.Interactive = False
                exapp.Interactive = True

                Return False
            Catch
                Return True
            End Try
        End If
    End Function

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;
            }
        }

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!