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

Discussion in 'Javascript' started by GaryB, Dec 1, 2005.

  1. GaryB

    GaryB Guest

    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
     
    GaryB, Dec 1, 2005
    #1
    1. Advertising

  2. GaryB

    VK Guest

    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>
     
    VK, Dec 1, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. goof1972
    Replies:
    0
    Views:
    6,612
    goof1972
    Dec 14, 2005
  2. Replies:
    2
    Views:
    370
    Andrew Thompson
    Dec 28, 2006
  3. srk
    Replies:
    0
    Views:
    692
  4. srk
    Replies:
    0
    Views:
    646
  5. Anukul Singhal
    Replies:
    2
    Views:
    148
    Anukul Singhal
    Mar 22, 2008
Loading...

Share This Page