views:

57

answers:

2

Hello,
I get the “Command Failed” exception when using the following code to insert content from one word 2007 document into another using bookmarks in c# :

string filePath = @“C:\temp\one.doc”;  
object trueObj = true;  
object falseObj = false;  
wordApp.Selection.InsertFile( filePath, ref missing, ref falseObj, ref trueObj, ref falseObj );

"one.doc" is another word document containing table content.

Error code: -2146824090. This error generally comes when the target object is disposed or unavailable. Not sure why I am getting it here.

Also when I remove table content from the target document and I just add formatted text, the operation succeeds. When the same operation is performed through word GUI, the operation works fine. Have scoured the internet for pointers on this issue, but none were helpful in resolving this.

Thanks in advance,
Bharath K.

A: 

We have solved this problem by defining a macro that performs the above actions and invoking the macro using c# from my program. That worked!

Bharath K
A: 

I encountered this problem and I noticed that range where to insert the file contains some locked content controls. Before using InsertFile command make sure that range (Selection here) does not contain locked content controls. Regards.

Bilel Boughanmi