Results 1 to 6 of 6

Thread: Javascript Microsoft word

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254

    Javascript Microsoft word

    Hi,
    does anyone have any knowledge of how to open a word application and put content into the document?

    Basically I will have a ( hidden ) text box on my form with HTML content in it. I want to open a word document and add the content of the text box onto the word document.

    Also is anyone aware of why word macros don't start when word is started via Javascript, whereas they do when you open it the normal fashion?

    thanks in advance.

    Lenin

  2. #2
    Lively Member Base's Avatar
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    65
    Hi,

    Yes it is possible to automate Word by Javascript, I've done it.
    Macro's don't start because of the way you installed Word on your server. You need to install it as an officeautomationuser.

    Code:
      wrdApp = Server.CreateObject("Word.Application");
      wrdApp.visible = false ; // can also set true, gives a nice efffect on the server when watching
      wrdApp.Documents.Open("C:\\your.doc"); 
      wrdApp.ActiveDocument.SaveAs(Bes);
    	
      wrdApp.ActiveDocument.Close(false);
      
      wrdApp.quit();
      wrdApp=undefined;
    Please not when the program doesn't work, your server will still leave Word open.

    Good luck.
    Ok

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Base,
    is the code provided not server side code? I was hoping for some Javascript client script which would take the contents of a browser control and add it as the contents of a new word document. Is this possible.


    Thanks in advance.

    Lenin

  4. #4
    scoutt
    Guest
    Javascript is client side scripting, not serverside. you can't do it by javascript or any script for that matter. that would be a security breach and it wouldn't let you. that code above looks more like ASP than javascript.

  5. #5
    Lively Member Base's Avatar
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    65
    The script is server side. You create the document on the server. Altough this is a secerity issue and office wasn't design to work that way.
    The client side script I don't know, but than offcourse you still have to need to write to the clients system.
    You can show the create Word document on the server as links and by clicking on them opening them in the browser what than acts as word with a browser touch.

    Good luck!
    Ok

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Scout,
    it can be done using client side VBScript. Try the following.


    <SCRIPT LANGUAGE=VBScript>

    Dim objWord


    Sub Btn1_onclick()
    call OpenDoc()
    End Sub

    Sub OpenDoc()

    Set objWord = CreateObject("Word.Application")

    objWord.Documents.Add

    objword.Selection.wholestory
    objWord.Visible = true
    objWord.Selection.TypeText myTextArea.value

    End Sub

    </SCRIPT>


    <HTML>


    <HEAD>

    <TITLE>Launch Word</Title>
    </HEAD>
    <BODY>
    <INPUT TYPE=BUTTON NAME=Btn1 VALUE="Open Word Doc">
    <Textarea name=myTextArea>ABCDE</TextArea>
    </BODY>
    </HTML>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width