public void btnSyncField_Click(IRibbonControl control) { var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument); var proptectionType = -1; try { proptectionType = doc.TurnOffProtection(string.Empty); var contentcontrol = Globals.ThisAddIn.Application.Selection.Range.ParentContentControl; if (contentcontrol == null) { return; } var matchingControls = Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTag(contentcontrol.Tag); foreach (WordOM.ContentControl mc in matchingControls) { mc.Range.Text = contentcontrol.Range.Text; } } catch (Exception e) { var logger = new EventViewerLogger(); logger.Log(e.ToString(), Type.Error); #if DEBUG MessageBox.Show(e.ToString(), @"sorry"); #endif } finally { doc.TurnOnProtection(proptectionType, string.Empty); } }
public void btnConvertToManual_Click(IRibbonControl control) { var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument); int p = doc.TurnOffProtection(string.Empty); doc.PopulateControl(Constants.WordContentControls.DocumentTitle, "Insurance Manual"); doc.TurnOnProtection(p, string.Empty); }