Saturday 9 February 2013

To Create an Excel Sheet

'TO  CREATE AN EXCELSHEET

'Set  xl = createobject("Excel.Application")
'        xl.Visible = true
'        xl.Workbooks.Add
'        xl.Cells(5,3).value = " automation"
'        xl.Cells(5,3).font.size = 13
'        xl.Cells(5,3).Font.ColorIndex = 25
'        xl.Cells(5,3).Font.Bold=true
'
'        xl.ActiveWorkbook.SaveAs("D:\qtp\test.xls")
'
'        xl.Quit
'
'        Set xl = Nothing



'To read input data from excelsheet
'
'   Set excel = createobject("Excel.application")
'
'   Set wbook = excel.Workbooks.Open("D:\qtp\test.xls")
'
'
'   Set wsheet = wbook.Worksheets("Sheet2")
'
'
'    rcount = wsheet.usedrange.rows.count
'    ccount = wsheet.usedrange.columns.count
'
'For row = 2 to rcount
'
'    userName = wsheet.cells(row,"A")
''    msgbox userName
'    passwd      = wsheet.cells(row,"B")
''    msgbox passwd
'    Dialog("Login").WinEdit("Agent Name:").Set userName
'    Dialog("Login").WinEdit("Password:").Set passwd
'
'Next
'
'
'user = Wsheet.cells(3,5).value
'


' compare two excel sheets

   flag = true

   Set excel = createobject("Excel.application")

   Set wbook = excel.Workbooks.Open("D:\qtp\test.xls")
   Set wsheet = wbook.Worksheets("Sheet1")


    Set wbook1 = excel.Workbooks.Open("D:\qtp\test1.xls")
   Set wsheet1 = wbook1.Worksheets("Sheet1")


   For each cell in wsheet.usedrange

'        msgbox cell.value
'        msgbox wsheet1.range(cell.address)
       If cell.value = wsheet1.Range(cell.address) Then
       
      else
             flag = false
             Exit for
       End If

   Next


   If flag = true  Then
       msgbox " both are same "
  else
       msgbox " both are different"
   End If

No comments:

Post a Comment