G
GordonS
I am getting the COM Exception from Word 2007 when I try to mark a range and
set the font in that range to “hiddenâ€.
Error message is “This method or property is not available because the
current selection is locked for format changes.â€.
The error code in the exception is -2146823683.
I am using Visual Studio 2008 to build a Word 2007 add-in project. Office
2007 is installed on my PC.
It is a new document and I haven’t yet closed it or made it visible to the
user. I appended some content to the end of the document in the form of a
couple of tables within content control groups. For each content control
group I set the LockContentControl propertyto false beforehand. The
LockContents property is not settable from code, but when I examine the
object after the exception using Visual Studio it says that LockContents is
set to true. How is this possible? How do I make the range editable?
I tried doing a search of the web for anything on this error but found
nothing. The error seems to indicate that it thinks Word has locked an area
of my document for format changes – if that is the case, how can I unlock the
entire document using C#.
The exception details are as follows:
System.Runtime.InteropServices.COMException was unhandled by user code
HelpLink="C:\\Program Files\\Microsoft
Office\\Office12\\1033\\WDMAIN11.CHM#37373"
Message="This method or property is not available because the current
selection is locked for format changes."
Source="Microsoft Word"
ErrorCode=-2146823683
StackTrace:
at Microsoft.Office.Interop.Word.FontClass.set_Hidden(Int32 prop)
at
Pilgrim.Office.Word.Utility.MSWordUtility.BackupSectionGroups(Application
objWord, Document objDoc, BillDataset objDataset, String& sErrorMessage) in
C:\25
Top\Client\Addin\Pilgrim.Office.Word\Pilgrim.Office.Word\Utility\MSWordUtility.cs:line 607
at Pilgrim.Office.Word.Utility.MSWordUtility.CreateBill(Application
objWord, String sTemplateName, BillDataset objDataset, String& sErrorMessage)
in C:\25
Top\Client\Addin\Pilgrim.Office.Word\Pilgrim.Office.Word\Utility\MSWordUtility.cs:line 323
at Pilgrim.Office.Word.PilgrimRibbon.btnNewBill_Click(Object sender,
RibbonControlEventArgs e) in C:\25
Top\Client\Addin\Pilgrim.Office.Word\Pilgrim.Office.Word\PilgrimRibbon.cs:line 228
at
Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
at
Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponent component, Object[] args)
at
Microsoft.Office.Tools.Ribbon.RibbonManager.Invoke(RibbonComponentCallback
callback, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture)
at
Microsoft.Office.Tools.Ribbon.RibbonManager.System.Reflection.IReflect.InvokeMember(String
name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:
The code sample is as follows:
objCopy.LockContentControl = false;
objCopy.Range.Select();
objWord.Selection.Font.Hidden = 1;
objCopy.LockContentControl = true;
objCopy is a ContentControl object of type group, and objWord is a reference
to Word.Application.
set the font in that range to “hiddenâ€.
Error message is “This method or property is not available because the
current selection is locked for format changes.â€.
The error code in the exception is -2146823683.
I am using Visual Studio 2008 to build a Word 2007 add-in project. Office
2007 is installed on my PC.
It is a new document and I haven’t yet closed it or made it visible to the
user. I appended some content to the end of the document in the form of a
couple of tables within content control groups. For each content control
group I set the LockContentControl propertyto false beforehand. The
LockContents property is not settable from code, but when I examine the
object after the exception using Visual Studio it says that LockContents is
set to true. How is this possible? How do I make the range editable?
I tried doing a search of the web for anything on this error but found
nothing. The error seems to indicate that it thinks Word has locked an area
of my document for format changes – if that is the case, how can I unlock the
entire document using C#.
The exception details are as follows:
System.Runtime.InteropServices.COMException was unhandled by user code
HelpLink="C:\\Program Files\\Microsoft
Office\\Office12\\1033\\WDMAIN11.CHM#37373"
Message="This method or property is not available because the current
selection is locked for format changes."
Source="Microsoft Word"
ErrorCode=-2146823683
StackTrace:
at Microsoft.Office.Interop.Word.FontClass.set_Hidden(Int32 prop)
at
Pilgrim.Office.Word.Utility.MSWordUtility.BackupSectionGroups(Application
objWord, Document objDoc, BillDataset objDataset, String& sErrorMessage) in
C:\25
Top\Client\Addin\Pilgrim.Office.Word\Pilgrim.Office.Word\Utility\MSWordUtility.cs:line 607
at Pilgrim.Office.Word.Utility.MSWordUtility.CreateBill(Application
objWord, String sTemplateName, BillDataset objDataset, String& sErrorMessage)
in C:\25
Top\Client\Addin\Pilgrim.Office.Word\Pilgrim.Office.Word\Utility\MSWordUtility.cs:line 323
at Pilgrim.Office.Word.PilgrimRibbon.btnNewBill_Click(Object sender,
RibbonControlEventArgs e) in C:\25
Top\Client\Addin\Pilgrim.Office.Word\Pilgrim.Office.Word\PilgrimRibbon.cs:line 228
at
Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
at
Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponent component, Object[] args)
at
Microsoft.Office.Tools.Ribbon.RibbonManager.Invoke(RibbonComponentCallback
callback, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture)
at
Microsoft.Office.Tools.Ribbon.RibbonManager.System.Reflection.IReflect.InvokeMember(String
name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:
The code sample is as follows:
objCopy.LockContentControl = false;
objCopy.Range.Select();
objWord.Selection.Font.Hidden = 1;
objCopy.LockContentControl = true;
objCopy is a ContentControl object of type group, and objWord is a reference
to Word.Application.