open word 2007 template like memo

T

tasleem

hi all i want to open word 2007 template like memo, and then write some text
into it using ATL C++, how to do that

any help is welcomed.
 
S

Shauna Kelly

Hi

You'll need to set a reference to the Word Application, which I assume you
can already do.

But, do you really want to open a template and write text into the template?
My guess is that you want to create a new memo and write text into the new
memo.

The way Word is designed to work is that you create a new document based on
a a template (.dot or .dotm or .dotx file). In the user interface that means
the user clicks the Round Office Pizza Button and then New, and selects the
template.

In code you use Word's Documents collection. With the Documents collection,
in general you *Open* an existing document, but you *Add* a new one.

To open an existing document you can do this (assuming appWord is a
reference to the Word application):

dim oDoc as Word.Document
set oDoc = appWord.Documents.Open(FileName:="myolddocument.doc" )
There are a dozen or so other parameters to the .Open method. Look up VBA
help for full details.

To create a new document you use the .Add method of the .Documents
collection, like this:

dim oDoc as Word.Document
set oDoc = appWord .Documents.Add(Template:="mytemplate.dot")
There are several other parameters of the .Add method, also described in the
VBA help.

Just for the record, this:
set oDoc = appWord .Documents.Add
oDoc.AttachedTemplate = "mytemplate.dot"
is *not* the same as this:
set oDoc = Documents.Add(Template:="mytemplate.dot")


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