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:

  • String functions in vbscript String functions in vbscript Below is the list of string functions in vb script lcase ucase len left right mid ltrim rtrim trim replace strreverse string Instr Instrrev strcomp We are going to have a look at each St… Read More
  • Difference between procedures and functions in vb script Difference between procedures and functions in vb script Major difference between procedures and functions in vb script is that procedures can not return the value but functions can return the value.Procedure Example… Read More
  • Sub Procedures in VBScript Sub Procedures in VBScript Sub procedures are used to perform the specific task. Sub procedures are used to increase the reusability of the code. Simple example of the procedure Suppose you want to find the sum of … Read More
  • Loops in Vbscript Loops in Vbscript Here is the list of different looping statements in vbscript. For ....Next For Each ...Next Do While...Loop Do Until....Loop While...Wend 'You can exit from For Loop with Exit For statement'For Loo… Read More
  • What are different conditional statements in vbscript? What are different conditional statements in vbscript? In Vbscript there are 2 types of conditional statements. if ...else Select Case Example of if else -  a = 10 If a > 10 Then Msgbox "a is greater t… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

150,603

Blog Archive