开发者

InsertFile operation in word 2007 document throwing “Command failed” exception

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.

T开发者_开发百科hanks in advance,

Bharath K.


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜