Attaching a template to word programmatically

G

guido

Hi,

is it possible to attach a template to a document, after it has been
created? I have the following code in JavaScript (it's for a web
application):

<script>
function openWord() {
var wordApp = new ActiveXObject("Word.Application");
wordApp.Visible = true;
wordApp.Documents.Open("http://localhost/dev/test1.doc");
//this alert shows "Normal.dot":
alert(wordApp.ActiveDocument.AttachedTemplate);
//and this also shows "Normal.dot":
alert(wordApp.Documents(1).AttachedTemplate);
//but this doesn't attach the template (i've tried putting the
template in other folders as well:
wordApp.Documents(1).AttachedTemplate =
"C:\Inetpub\wwwroot\dev\test1.dot"
}
</script>

....should this work? what should the code look like?

Thanks in advance.
 
G

guido

Ok - found out how to do this - i needed to put the template in the
startup folder.

....however...the template i am trying to attach has a footer which i
want to apply to the word .doc. I can see from the alert:
"alert(wordApp.Documents(1).Att­achedTemplate); " that the test1.dot
template has been attached, but i cannot see the footer in my document
- any ideas?

thanks.
 
C

Cindy M -WordMVP-

Hi Guido,
Ok - found out how to do this - i needed to put the template in the
startup folder.
Actually, you probably don't want to do that. It won't attach the
template to a document, it will just slow down the Word startup process.
Templates in the Startup folder are just there to provide toolbars,
AutoText and macros.

There's no way to have a template automatically add content to a
document, once that document has been created. You'd need to actually
automate the document. Building on your bit of sample code, in pseudo
Java (VBA to look like Java), I'd create a footer like this:

wordDoc = wordApp.Documents.Open("http://localhost/dev/test1.doc");
footerRng = wordDoc.Sections(1).Footers(1);
footerRng.Text = "content for the Footer" + Chr(9) + "including Tabs to
position" + Chr(9) + "right-aligned, last";
....however...the template i am trying to attach has a footer which i
want to apply to the word .doc. I can see from the alert:
"alert(wordApp.Documents(1).Att­achedTemplate); " that the test1.dot
template has been attached, but i cannot see the footer in my document
- any ideas?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
G

guido

Thanks alot Cindy. The code worked very well.
Any suggestions for a good word automation reference website?

Thanks again,
Guy.
 
C

Cindy M -WordMVP-

<[email protected]>
<VA.0000aa14.0060bbbb@speedy>
<[email protected]>
Newsgroups: microsoft.public.office.developer.automation
NNTP-Posting-Host: 229.11.78.83.cust.bluewin.ch 83.78.11.229
Path: number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!msrtrans!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
Lines: 1
Xref: number1.nntp.dca.giganews.com microsoft.public.office.developer.automation:9546

Hi Guido,
Any suggestions for a good word automation reference website?
There's some code on word.mvps.org...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8
2004)
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