By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,451 Members | 994 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,451 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Dec 1 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
VK

GaryB wrote:
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>

Dec 1 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.