Excel 2013 worksheet activate

前端 未结 9 1790
情话喂你
情话喂你 2021-01-03 03:28

I have an issue with activating a sheet from a user form, the same code works fine in Excel 2003 to Excel 2010, doesn\'t work with Excel 2013.

This is how to simply

9条回答
  •  时光取名叫无心
    2021-01-03 03:33

    The workaround for the above Excel 2013 worksheet activation through automation bug is below (c#):

    public static void ActivateSheetAndWorkaroundExcel2013VBASheetActivationBug( Worksheet oSheet2Activate )
    {
        if( oSheet2Activate.IsNull() )
            return;
    
        oSheet2Activate.Activate();
    
        // Excel 2013 has problems activating worksheet through automation
        // https://www.google.com/webhp?ie=utf-8&oe=utf-8#q=excel+2013+worksheet+activate+problem+
        // http://stackoverflow.com/questions/18726141/excel-2013-worksheet-activate
        // 
        // The only way to reset the Excel 2013 state is to hide/show the active window
        if( Application.Version == "15.0" )
        {
            Window oActiveWnd = Application.ActiveWindow;
            oActiveWnd.Visible = false;
            oActiveWnd.Visible = true;
            oActiveWnd.Activate();
        }
    }
    

    Call that helper method instead of directly calling oSheet.Activate(). You're welcome:-)

提交回复
热议问题