WScript syntax for creating a new document based on a Word template

G

GaryB

Hi,

(Posted this in scripting.wsh before I realised that it might be better
placed here - sorry if you;ve got two copies)

I want my (IE) Intranet users to be able to create a new Word document
based on a specified template.

The following works, but I would like to be able to pass the filename
as a parameter, as there are often multiple documents on the same page:

---------------Script Code Starts-------------
<script lang="Javascript1.2">

function NewDoc()
{
var oShell
oShell = new ActiveXObject ("WScript.Shell");
oShell.Run('cmd /K "C:\\Test.dot"', 0, false);
window.event.cancelBubble = true;
return false;
}
</script>
---------------Script Code Ends-------------


---------------Link Code Starts-------------
<a href=":" onclick="return NewDoc()">Create a new document based on
C:\Test.dot</a>
---------------Link Code Ends--------------

I know to specify the document template name as follows:

---------------Link Code Starts-------------
<a href=":" onclick="return NewDoc('C:\\Test.dot')">Create a new
document based on C:\Test.dot</a>
---------------Link Code Ends--------------

And change the "Function NewDoc()" in the script code to line to
"Function NewDoc(TemplateName)". The problem is that I don't know what
syntax to use to parametise the
"oShell.Run('cmd /K "C:\\Test.dot"', 0, false);"
line.

Thank you very much - and, while I'm at it, if you are able to point me
to a library of WSH sample files and/or a resource for learning how to
use WSH within an Intranet context, I'd be very grateful.

Regards

Gary Bartlett
 
V

VK

GaryB said:
Hi,

(Posted this in scripting.wsh before I realised that it might be better
placed here - sorry if you;ve got two copies)

I want my (IE) Intranet users to be able to create a new Word document
based on a specified template.

Note 1: you have to double backslashes in the path!

Note 2: if you have any further questions about the JavaScript part you
are welcome. But the usage of WScript.Shell goes beyond the scope of
this group IMHO. You should insist on the answer in the related
newgroup.

<html>
<head>
<title>Word</title>
<script type="text/javascript">
var oShell = null;

function init(path) {
oShell = new ActiveXObject('WScript.Shell');
oShell.Run('winword.exe /t '+path, 1, false);
}

</script>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" onload="init('c:\\Template.doc')">

</body>
</html>



Thank you very much - and, while I'm at it, if you are able to point me
to a library of WSH sample files and/or a resource for learning how to
use WSH within an Intranet context, I'd be very grateful.

You may start from here:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthrun.asp>
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top