.NET (C#) and Word Application

E

Emil

Hi all,

I’m a C++ developer and a very beginner in both C# (.Net) and Word
Programming. What my company wants next is something like this: from
different texts to build a Word 2007 document and then open this in the real
Word 2007 application to give the user the possibility to change the document
as usual with all possibilities (Menüs, Panels, etc.). Well my problem is
that the Word 2007 must be embedded in our C# - Application (WinForms).
Knows somebody a solution to do this: embed the Word 2007 application in
WinForms or if better maybe in WPF? For any idea thank you in advance.

Best Regards,
Emil
 
S

Shauna Kelly

Hi Emil

I would re-think this.

What the user needs is to have Word 2007 running with a document that
contains your text. So what you need to do is:

1. Get a reference to an existing open copy of Word 2007 or, if there
isn't one, open Word.
For some sample VBA code of this kind, see
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm


2. Tell Word to create a new document, based on whatever template is
appropriate.
In VBA-speak that would be:
Dim oDoc as Word.Document
'assume appWord is a reference to the open Word application
set oDoc = appWord.Documents.Add
Template:="c:\wherever\whatever.dot"


3. Fill up that document with your text.
oDoc.Range.InsertAfter "My text here"


4. Leave the user to do their work.


The interesting bit here is to work out how you'll add the text if it is
formatted in any way. My advise is to investigate BuildingBlocks in Word
and, as much as possible, create them (by hand, in Word) and insert them
into your document (in your code). A BuildingBlock can contain anything:
a single word or 20 pages of formatted text, pictures and tables. See
the following, about AutoTexts, which are one kind of BuildingBlock:

Using AutoText
http://www.word.mvps.org/FAQs/Customization/AutoText.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top