Add Content Controls Runtime

Oct 21, 2011 at 1:04 PM

Hello there...

I want to add different content controls in word document. I have an object of NetOffice.WordApi.Document. Can you please paste some sample code snippet ?

Some like.......?

Dim oContentControl = DirectCast(CurrentDocument.ContentControls, NetOffice.WordApi.ContentControl)      oContentControl.Application.ActiveDocument.ContentControls.Add(NetOffice.WordApi.Enums.WdContentControlType.wdContentControlText, oRange)

Thanks in advance.



Oct 21, 2011 at 2:12 PM
Edited Oct 21, 2011 at 2:13 PM

of course.

Dim oContentControl As Word.ContentControl = wordApplication.ActiveDocument.ContentControls.Add(NetOffice.WordApi.Enums.WdContentControlType.wdContentControlText, oRange)


Oct 24, 2011 at 6:07 AM

Hey Sebastian,

First would like to thank you for quick response.

I am done with adding differnt kind of content control. Now only one thing is peniding which CheckBox conent control.


oContentControl = oContentControls.Add(NetOffice.WordApi.Enums.WdContentControlType.wdContentControlCheckBox, oRange).

This is resulting into adding text cotrol NOT checkbox contol :(. Except this every type of controls are added well. I read on one forum that it is introduced from 2010. I still see it is working fine in 2007. Can you please suggest me some code block so that I can add checkbox content control.

Thanks in advance.




Oct 24, 2011 at 2:02 PM
Edited Oct 24, 2011 at 2:04 PM

i have bad news for you.

wdContentContolCheckbox is a 2010 specific enum member.

NetOffice helps you with IntelliSense Text to see which version supports a specific entity.
looks like this

// Summary 
// SupportByLibrary Word 12, 14 
public enum WdContentControlType 
  // Summary: 
  // SupportByLibrary Word 14
  wdContentControlCheckBox = 8

moreover its possible to analyze your assembly which office version is compatible with your code with the netoffice developer toolbox.