Thursday, January 3, 2019


How to create a word document using vbscript

' Create and Save a Word Document

'Create the Word object
Set objWord = CreateObject("Word.Application")

'Set the caption of the Word
objWord.Caption = "Welcome to Automated Word Script"
objWord.Visible = True

'Add new document
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

objSelection.Font.Name = "Arial"
objSelection.Font.Size = "18"
objSelection.TypeText "" & Date()
objSelection.TypeParagraph()
objSelection.TypeParagraph()

objSelection.Font.Size = "10"



'Start writing to the word document

For i=0 to 10

    objSelection.Font.Bold = True
    objSelection.TypeText "Square of   " & i & " is " & i*i
    objSelection.Font.Bold = False
    objSelection.TypeParagraph()
    objSelection.TypeParagraph()

Next

'finally save the document.
objDoc.SaveAs("C:\mydoc.doc")

'Quit the application
objWord.Quit


Related Posts:

  • What are the different operators in vbscript? What are the different operators in vbscript? At broad level there are 3 kinds of operators as mentioned below. Arithmetic Operators Comparison Operators Logical Operators Arithmetic Operators in the order of pre… Read More
  • Types of variables in Vbscript Types of variables in Vbscript Variables are storage locations in memory where we can store the the values.In vb script there are 3 types of variables. Scalar  - contains only one value. Array - contains many val… Read More
  • Classes in VBScript Classes in VBScript Here is an example that shows how we can create a class in QTP. Once we define the class, we can create its objects and then access its method and properties. 'declare the class book. Class Bo… Read More
  • Error handling in VBScript Error handling in VBScript VBScript provides below statements and keywords to handle errors. on error resume next Err object - err.description, err.number Sample code to handle the error is given below If er… Read More
  • Data Types in vbscript Data Types in vbscript In vb script all variables are initialized with the data type called variant. But we can have below sub-types in vb script. In below table we have mentioned all sub data types in vb sc… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

151,865

Blog Archive