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
'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
0 comments:
Post a Comment