Monday, 10 March 2014

QTP Word Object Model

To create word file with seo.doc name Dim wordobj Set wordobj = CreateObject("Word.Application")  wordobj.Visible =  True  wordobj... thumbnail 1 summary
To create word file with seo.doc name

Dim wordobj

Set wordobj = CreateObject("Word.Application")
 wordobj.Visible =  True
 wordobj.Documents.Add
 wordobj.ActiveDocument.SaveAs "c:\seo.doc"
 wordobj.Quit

 Set wordobj=Nothing



To create xl file with name seo.xl

Dim xlobj

Set xlobj = CreateObject("Excel.Application")
 xlobj.Visible =  True
xlobj.Workbooks.Add
xlobj.Cells (1,1)="Testing"             
xlobj.Cells (2,1)="QTP"
xlobj.ActiveWorkbook.SaveAs "c:\seo.xl"
xlobj.Quit

Set xlobj=Nothing
--------------------------------------------------------------------------------------------------------------------------
'Create a Word document
Dim objWord
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Add
objWord.ActiveDocument.SaveAs "C:\Documents and Settings\Administrator\Desktop\abcde.doc"
objWord.Quit

Set objWord = Nothing

-------------------------------------------------------------------------------------------------------------
Dim objWord, objDocument, objRegEx, Matches
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDocument = objWord.Documents.Open ("C:\Documents and Settings\Administrator\Desktop\abcde.doc")

myContent = objDocument.Content

Set objRegEx = New RegExp
objRegEx.Pattern = "QTP"
objRegEx.IgnoreCase = True
objRegEx.Global = True

Set Matches = objRegEx.Execute(myContent)
Msgbox Matches.Count

objDocument.Save
objDocument.Close
objWord.Quit

Set objWord = Nothing

Set objRegEx = Nothing



------------------------------
Creating a Microsoft Word document 

Example:
Dim objWD

‘ Create the Word Object
Set objWD = CreateObject(“Word.Application”)

‘ Create a new document
objWD.Documents.Add

‘ Add text to the document
objWD.Selection.TypeText “This is some text.” & Chr(13) & “This is some more text”

‘ Save the document
objWD.ActiveDocument.SaveAs “c:\temp\mydoc.doc”

‘ Quit Word
objWD.Quit

‘ Release the Word
--------------------------------------------------




No comments

Post a Comment