Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2008 C# .NET Word
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:
 

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 11-May-11 0:31am
2000 P569
Edited 11-May-11 3:50am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
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();
  Permalink  

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

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 11 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100