QTP Excel Word

III) Working with Word Docs

a) Create a word document and enter some data & save


Dim objWD
Set objWD = CreateObject("Word.Application")
objWD.Documents.Add

objWD.Selection.TypeText "This is some text." & Chr(13) & "This is some more text"
objWD.ActiveDocument.SaveAs "e:\gcreddy.doc"
objWD.Quit

IV) Working with Excel Sheets

a) Create an excel sheet and enter a value into first cell


Dim objexcel
Set objExcel = createobject("Excel.application")
objexcel.Visible = True
objexcel.Workbooks.add
objexcel.Cells(1, 1).Value = "Testing"
objexcel.ActiveWorkbook.SaveAs("f:\gcreddy1.xls")
objexcel.Quit

b) Compare two excel files


Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("E:\gcr1.xls")
Set objWorkbook2= objExcel.Workbooks.Open("E:\gcr2.xls")

Set objWorksheet1= objWorkbook1.Worksheets(1)

Set objWorksheet2= objWorkbook2.Worksheets(1)

For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
msgbox "value is different"
Else
msgbox "value is same"
End If
Next
objWorkbook1.close
objWorkbook2.close
objExcel.quit
set objExcel=nothing

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.