Hi everybody,
Can you please tell me how to copy a metafile object in a clipboard and paste it in MS WORD 2007.
Code snippets will be more helpful.
Hi everybody,
Can you please tell me how to copy a metafile object in a clipboard and paste it in MS WORD 2007.
Code snippets will be more helpful.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mike Hankey62 reputationPosted Jul 13, 2008, 8:51 PM EDT
Meta files are not very well documented and when developing ClipSpy+ I omitted them because I couldn't find much help.
The ClipSpy+ application won't answer your problem but it is a tool you can use to do further investigation.
Mike
Nathan NZ15 reputationPosted Jul 14, 2008, 12:33 AM EDT
Thanks Mike,
After googling and thru some forums I came to know that Clipboard can be used to export images to word. I was able to copy the images in clipboardbut while posting to word I am getting the exception as "Excetion occured due to no data in clipboard or the data is not correct". I suspect this is related to the DataFormat I am copying in the Clipboard but I dont know how to resolve it.
Any Ideas?
Mike Hankey62 reputationPosted Jul 14, 2008, 3:41 PM EDT
Need a little more information about what your doing and how your doing it. Language, code on how your attempting to do it, etc.. Something!
Mike
Nathan NZ15 reputationPosted Jul 14, 2008, 8:51 PM EDT
Thanks for the reply Mike.
My task is to export a metafile image displayed on the screen to MS WORD 2007.
Metafile image is displayed as MetafileNode(using syncfusion suite). I am using C# and Visual Studio Tools for Office to accomplish this. Through VSTO forums I came to know that metafile image can be stored in memory stream and can be pasted to word using the word.doc.Paste method. I copied metafile to clipboard with the command Clipboard.SetData(DataFormats.EnhancedMetafile, metanode.Image); // metanode.Image returns a Metafile Object
When I paste using Doc.ActiveWindow.Selection.paste() I get Command Failed Error (800A1066).
Where I am going wrong?
And is it possible tocopy and paste the metafile using memory(stream) without using Clipboard.
Waiting for early reply.
Mike Hankey62 reputationPosted Jul 15, 2008, 8:45 PM EDT
Try just using the Clipboard.SetImage() to do the paste and don't worry about it being a MetaFile. If I remember right it takes care of the formatting for you. I wrote a RichEditControl (See my article here) if you have any questions.
To bypass that problem in the RichTextControl I just copied the image to the Clipboard using the SetImage() method and pasted it into the control at the current location. Turns out that thats a WHOLE lot easier than wrestling with formats.
Sorry its taken so long to get back to you, evidently they don't notify you when you post a reply.
Good Luck,
Mike
Nathan NZ15 reputationPosted Jul 16, 2008, 2:52 AM EDT
Thank you Mike,
There were 2 methods to accomplish my task
1.Create the metafile and save it disk. Then use Shapes.AddPicture(filename) to insert it into word in desired location.
2.Create the memorystream for the metafile, copy it directly to WORD(I dont know how it is done) or put it on Clipboard and insert it using Paste Method.
I follwed the method 1 and got the solution. I was trying out for the 2 method and even now I am hanging around that.
Anyhow method 1 got Okeyd by the team(for time being).
Still if you have any Idea regarding method 2 please share. Can it be accomplished?
Thank you very much for your time Mike.
Mike Hankey62 reputationPosted Jul 18, 2008, 1:39 PM EDT
There are various types of memory streams, I'm sure what your wanting to do is possible, maybe with a binary stream??
Not sure and I'd hate to lead you on a goose chase. I used memory streams to a lesser extent in my ClipSpy+ application and I know the Clipboard uses them to some extent but??
Sorry can't help you more!
Mike
Nathan NZ15 reputationPosted Jul 21, 2008, 6:41 PM EDT
Hi Mike,
Thanks for your reply and valuable time.
Currently I am going with the method1 (as specified above) so no problems.
Nathan