Question

I have a MS Word document and that document has multiple content control. When user copies entire data from one content control to another sometimes it copies content control itself with data and when user pastes data it creates nested content control.

Question: Somehow I need to restrict Word document so that user can only modify data and additional content control cannot be created. How can I achieve this.

Was it helpful?

Solution

I don't think there is a setting in Word that can control this; there isn't a content control property that does.

So I think you're looking at a VSTO Word Add-In, or possibly a VBA macro.

With VSTO, have a look at the content control event model. Maybe Document.ContentControlAfterAdd fires on paste? Googling .. apparently it does, subject to an issue

when the content controls are in table cells, and the user chooses to insert a column: the BeforeDelete is fired for all the content controls in the table, but AfterAdd is not raised when the column insertion completes.

Check out the other content control related events as well - start by seeing which fire when the user does what you are concerned about, and of course, what other situations they fire in (which your code will have to ignore).

Otherwise, you could try a more generic way of capturing paste. There is:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top