public void OnWindowActivate(object workbook) { if (IsConnected) { Excel._Workbook book = this.Parent as Excel._Workbook; if (book != null) { try { string parentBookFullName = (string)book.GetType().InvokeMember( "FullName", System.Reflection.BindingFlags.GetProperty, null, book, null, CultureInfo.CurrentUICulture); string workbookFullName = (string)workbook.GetType().InvokeMember( "FullName", System.Reflection.BindingFlags.GetProperty, null, workbook, null, CultureInfo.CurrentUICulture); if (string.Compare(parentBookFullName, workbookFullName, true) == 0) { Excel._Worksheet sheet = book.ActiveSheet as Excel._Worksheet; if (sheet != null) { try { if (String.Compare(sheet.Name, Worksheet, true) == 0) { adxClearTimesheet.Enabled = true; adxRibbonButtonClearTimesheet.Enabled = true; } } finally { Marshal.ReleaseComObject(sheet); } } } } catch (Exception err) { MessageBox.Show(err.Message, err.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } }