Automating creation of document with word within .net

S

Simon Verona

I want to create a Word document based on a template and display the
document ready for editting by the user.

Once the user has finished editting, they will save the document and close
word, I want to then pick up the document and copy it up to a server.

This is in vb.net. So far, I've managed to create the document and save it
away (so it knows the file location I wat it in) using the following code:


Dim LetterName As String = "c:\dms\forms\" & filename
Dim word As New Word.ApplicationClass
Dim doc As Word.Document
Debug.WriteLine("AppPath=" & System.Windows.Forms.Application.StartupPath)
Try
doc = word.Documents.Add(System.Windows.Forms.Application.StartupPath &
"\Dms Mailmerge.dot")
Catch ex As Exception
Debug.WriteLine("error = " & ex.InnerException.Message)
End Try
doc.SaveAs(LetterName)
word.Visible = True
word.Application.Activate()

I can't however, work out what to do next to pick up when Word is closed and
the file is saved? The vb.net application just carries on after the last
statement above.

Any thoughs ?

Regards
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 
C

Cindy M -WordMVP-

Hi Simon,
I want to create a Word document based on a template and display the
document ready for editting by the user.

Once the user has finished editting, they will save the document and close
word, I want to then pick up the document and copy it up to a server.

This is in vb.net. So far, I've managed to create the document and save it
away (so it knows the file location I wat it in) using the following code:


Dim LetterName As String = "c:\dms\forms\" & filename
Dim word As New Word.ApplicationClass
Dim doc As Word.Document
Debug.WriteLine("AppPath=" & System.Windows.Forms.Application.StartupPath)
Try
doc = word.Documents.Add(System.Windows.Forms.Application.StartupPath &
"\Dms Mailmerge.dot")
Catch ex As Exception
Debug.WriteLine("error = " & ex.InnerException.Message)
End Try
doc.SaveAs(LetterName)
word.Visible = True
word.Application.Activate()

I can't however, work out what to do next to pick up when Word is closed and
the file is saved? The vb.net application just carries on after the last
statement above.

Any thoughs ?
You'd probably need to sink the DocumentClose and/or ApplicationQuit events.
This means you need to declare the object variable Word at the global level so
that it doesn't go out of scope when your procedure ends.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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