Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi
I am facing problem while copying a shape from word(2007) document. How to copy a shape from word using bookmark? Could some one help me?
This is what i am doing:


MIDL
object FileName = objTemplateFile;
object oMissing = System.Reflection.Missing.Value;                    
object oWhat = WdGoToItem.wdGoToBookmark;
object oName = "MyBookmark";
//Opening source document in hidden mode
objWord = wordApp.Documents.Open(ref FileName, ref oFalse, ref oTrue, ref oFalse, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oFalse, ref  oFalse, ref oMissing, ref oTrue, ref oMissing, ref oMissing);

objWord.Bookmarks.get_Item(ref oName).Range.Select();
objWord.Range(ref oMissing, ref oMissing).Copy();
//Copy the shape in to target dc
wordApp.ActiveWindow.Selection.Paste();      
Posted
Updated 11-May-11 2:50am
v3

1 solution

Seems that you're finding the bookmark correctly, but then copying it wrong. You're selecting (highlighting) the contents of the bookmark, but then actually copying the contents of a different range (when you go objWord.Range(ref oMissing, ref oMissing) you're basically identifying the entire document body, because you didn't specify the start and end positions).

I think the correct code would be:
C#
objWord.Bookmarks.get_Item(ref oName).Range.Copy(); // Copy range directly instead of selecting it and then trying to copy it

//Copy the shape in to target dc
wordApp.ActiveWindow.Selection.Paste();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900