Results 1 to 2 of 2

Thread: make it run in VBScript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    I've written a simple program in VB, which creates an instance of a Word application, enters some text, and saves the document.

    Here is a sample of what I have:

    Code:
     Set objWord = New Word.Application
     Set doc1 = objWord.Documents.Open("c:\temp\report.doc")
            
        With objWord.Selection
            
            .EndKey Unit:=wdStory
            .Tables.Add Range:=objWord.Selection.Range, NumRows:=1, NumColumns:=5
            .TypeText Text:="First Name"
            .MoveRight Unit:=wdCell
            .TypeText Text:="Last Name"
            'do more editing of the document here
        End With
        
            
        'save the file
        doc1.SaveAs FileName:="c:\temp\report1.doc"
        doc1.Close
        objWord.Quit
    it works fine. But what I want to do now is have this run in VBScript. I know that from VBScript I can create an instance of a Word Application, but when I tried to run this as above, it screamed at me when it tried to compile
    Code:
            .EndKey Unit:=wdStory
    Could someone please indicate why this will not work in VBScript. Or can I even do this in VBScript. Does anyone know of a resource where I can find how to refer to the Word Object Model in VBScript ??

    tx

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Well, the simple problem is that VBScript doesn't like to use the With statement with objects that are not in its own object library. Try taking the With Statement out and putting the objWord.Selection infront of the other lines. The object model in VBScript is the same as it is when you're in VB or Word itself. You can use the Word VBA Help File or go to http://msdn.microsoft.com/officedev/.

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