-
June 17th, 2008, 02:47 PM
#1
copy word document in c#
Hi,
I have a add-in written in c#( vs2005 ) for MSWord( 2003 ).
I am trying to find a technique to copy the contents of loaded word document ( images, formatting etc. ) and create a new document from c# and paste the contents into this new document. This is what i got so far:
Code:
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();
Object oMissing = System.Reflection.Missing.Value;
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
oWordDoc.ActiveWindow.Selection.WholeStory();
oWordDoc.ActiveWindow.Selection.Copy();
oWord.ActiveDocument.Select();
oWordDoc.ActiveWindow.Selection.PasteAndFormat(Word.WdRecoveryType.wdPasteDefault);
To test i follow this procedure:
Set startup app in VStudio to MSWord.
Hit F5.
VS open a new word doc.
Put some text and an image in it.
Save the document.
Click the Pluin button.
When the code above to copy contents runs, MSWord comes up with an error saying cannot read contents of this document. Repair this document.
Code does not crash or anything.
Is there a way to copy a word document loaded from c#.
Last edited by 2kaud; November 16th, 2018 at 09:09 AM.
Reason: Fixed code tags
-
June 17th, 2008, 03:27 PM
#2
Re: copy word document in c#
sorry. My bad. It works. I had the loading path wrong.
-
June 17th, 2008, 04:12 PM
#3
Re: copy word document in c#
Another problem with same component. It only works if you start MSWord and if it opens a new document.
e.g If you go to program files->office->msword, word starts and loads a new document by default. The add-in button is available in commandbar and if user clicks, it behaves as it should.
But if you double click on an existing document or start word and open an existing file, clicking on the add-in button does nothing!!!
Can anyone please help regarding this. I have been searching web about this for over 3 days, with no results. I am really stuck on this , as without the plug-in being functional from a Word template, it is useless.
-
June 18th, 2008, 09:45 AM
#4
Re: copy word document in c#
36 views and no suggestions?
-
June 18th, 2008, 10:20 AM
#5
Re: copy word document in c#
Originally Posted by venAdder
36 views and no suggestions?
What do you think that means?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|