Results 1 to 6 of 6

Thread: Word Doc in VBScript

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Word Doc in VBScript

    Guys

    I'm playing around with this bit of code:
    VB Code:
    1. <script language="vbscript">
    2.       Dim WordApp
    3.       Dim WordDoc
    4.       Dim WordPath
    5.  
    6.         Set WordApp = CreateObject("Word.application")
    7.         Set WordDoc = WordApp.Documents.Add()
    8.         set WordPath = Server.MapPath("C:\file.doc")
    9.        
    10.         WordDoc.Document.Open(WordPath)
    11.        
    12.         WordApp.Visible = true
    13.        
    14.         WordDoc.Document.Print()
    15.        
    16.         WordDoc.Document.Close
    17.    
    18.         Set WordDoc = Nothing
    19.         Set WordApp = Nothing      
    20.  
    21.         </script>

    Now, it launches winword.exe, but that's about it. What am I doing wrong?!

    Peter
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Word Doc in VBScript

    The problem is that you are using "WordDoc.Document" rather than just "WordDoc" as you should be (as WordDoc is a document object).

  3. #3

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: Word Doc in VBScript

    Changed it to WordDoc.Open("C:\file.doc") and the same thing happens.
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Word Doc in VBScript

    Ah wait, I'd not thought about that one enough! The code should be like this:

    VB Code:
    1. Dim WordApp
    2. Dim WordDoc
    3. Dim WordPath
    4.  
    5.   Set WordApp = CreateObject("Word.application")
    6.   Set WordPath = Server.MapPath("C:\file.doc")
    7.   Set WordDoc = WordApp.Documents.Open(WordPath)
    8.        
    9.   WordApp.Visible = true
    10.  
    11.   WordDoc.Print()  'I havent tested this line
    12.   WordDoc.Close
    13.    
    14.   Set WordDoc = Nothing
    15.   Set WordApp = Nothing

  5. #5

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Re: Word Doc in VBScript

    Still no joy!
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Word Doc in VBScript

    Well is seems similar to the example in this FAQ thread, except for WordPath which may not have a valid path in it.

    I would recommend commenting out the Print and Close lines for now, just to see if the document is actually opened (if not, check what WordPath contains).

    Once that is ok, uncomment the Close line and test that. Then you can check the Print line, which I think may not be correct code.

    edit: it's not correct, it should be PrintOut like this:
    VB Code:
    1. WordDoc.PrintOut BackGround:=False

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