Results 1 to 2 of 2

Thread: getting to Word in VBScript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    I posted this in the VB Forum.. but I think it's more applicable to this forum.. hope someone knows:

    I have an event handler on a web page, which upon a button click will create an instance of a word application on the server and do some stuff to it.

    I'm having trouble getting this to work...

    Here is the code that I have, upon button click nothing seems to happen. No errors, no file created...


    Code:
    <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript runat=server>
    <!--
    
    Sub report_button_onclick
    Set ObjWord =  CreateObject("Word.Application")
        Set doc1 = ObjWord.Documents.Open("c:\temp\report.doc")
            
       
            ObjWord.Selection.EndKey Unit=wdStory
            ObjWord.Selection.Tables.Add Range=ObjWord.Selection.Range, NumRows=1, NumColumns=5
            ObjWord.Selection.TypeText Text="First Name"
            ObjWord.Selection.MoveRight Unit=wdCell
            ObjWord.Selection.TypeText Text="Last Name"
            ObjWord.Selection.MoveRight Unit=wdCell
            ObjWord.Selection.TypeText Text="Phone Number"
            ObjWord.Selection.MoveRight UnitwdCell
            ObjWord.Selection.TypeText Text="FaxNumber"
    		 ObjWord.Selection.MoveRight Unit=wdCell
            ObjWord.Selection.TypeText Text="Building"
            ObjWord.Selection.MoveRight Unit=wdCharacter, Count=1
            ObjWord.Selection.InsertRows 1
            ObjWord.Selection.MoveLeft Unit=wdCharacter, Count1
            
        
        stmSQL = "SELECT * FROM table1 WHERE Building = 'b2'"
        Set oRS = CreateObject("ADODB.Recordset")
       
        'Open the connection.
        oRS.Open stmSQL, "DSN=bdata"
        oRS.MoveFirst
              
           
        Do While Not oRS.EOF
              
            fn = oRS("FirstName")
            ln = oRS("LastName")
            ph = oRS("WorkPhone")
            fx = oRS("FaxNumber")
            bldg = oRS("Building")
                    
                ObjWord.Selection.MoveRight Unit=wdCharacter, Count=1
                ObjWord.Selection.InsertRows 1
    			  ObjWord.Selection.MoveLeft Unit=wdCharacter, Count=1
                ObjWord.Selection.TypeText Text=fn
                ObjWord.Selection.MoveRight Unit=wdCell
                ObjWord.Selection.TypeText Text=ln
                ObjWord.Selection.MoveRight Unit=wdCell
                ObjWord.Selection.TypeText Textph
                ObjWord.Selection.MoveRight Unit=wdCell
                ObjWord.Selection.TypeText Text=fx
                ObjWord.Selection.MoveRight Unit=wdCell
                ObjWord.Selection.TypeText Text=bldg
            oRS.MoveNext
       
       Loop
    
       'Close the Recordset object.
       oRS.Close
              
              
        'save the file
        doc1.SaveAs FileName="c:\temp\report1.doc"
        doc1.Close
        
        ObjWord = Nothing
    
    
    End Sub
    
    -->
    </SCRIPT>
    Any ideas why this isn't producing desired results?
    I originally wrote this code in VB, and am trying to adapt it to VBScript so that it runs on my webpage...The methods I'm using on the word object may not even be valid.??

    Suggestions would be appreciated!

    tx
    dvst8

  2. #2
    Guest
    well, there's a couple of issues. Do you want users who go to your web page and already have Word installed on their local machine or - (judging from the runat server code) are you trying to make the server "dish out" an instance of Word to the visitor of your page?

    Well, the first part is do-able but will require that the user adjusts their security settings in Internet Explorer Only so as to allow the web page to create an instance of an application(Word) on their own machine. This is a huge security/pain in the ass, i suggest not doing it.

    The other option is trying to get the server to send an instance of Word to every visitor of the page. It can't work first of all, and second of all in can't work. I think(hope) I'm "reading" the code incorrectly.

    If Word is installed on the server where the ASP script is running you can create an instance of word, manipulate it on the server, and send the doc back to the browser but Word is an out-of-process application which has a few issues: if your web host allows you to create an instance of Word on the server, change web hosts.

    If you're planning on doing it on your own server be aware that out-of-proc components are resource hogs and Word was never designed to be robust web app(not yet anyway). Allowing IIS to run Word means allowing the IUSR account to run any executables on the web server which is very very very bad, unstable, insecure-there are ways around it that do not outway the costs of running executables freely on a web server. Performance would be the biggest hit. How much memory does an instance of word take up? Now multiply that by however many users are hitting the page that creates the instance-that's a huge resource hog and performance slug.

    for performance, security, and stability, i suggest maybe designing some nice html templates that you could stamp that info into and really "web-a-fy" those Word reports. Just my two cents.
    -pvb

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