File System Object (FSO) - Working with Excel Files

'Create an excel file, add data to it, and save it at specified location
Dim Objexcel
Set Objexcel = CreateObject("Excel.Application")
Objexcel.Visible  = True
Set Objworkbook = Objexcel.Workbooks.Add
Set Obssheet = Objworkbook.Worksheets (1)
Obssheet.cells(1,1).value = "This is some text"
Objworkbook.Saveas "C:\Amol"
Objworkbook.Close
Objexcel.Quit
Set Objexcel = Nothing
Set Objworkbook = Nothing
Set Obssheet = Nothing

'Read and wite data from and in excel file
Dim Objexcel
Set Objexcel = CreateObject("Excel.Application")
Objexcel.Visible  = True
Set Objworkbook = Objexcel.Workbooks.Open("D:\gcr1.xlsx")
Set Obssheet = Objworkbook.Worksheets (1)
Var = Obssheet.cells(1,1).value
Msgbox Var
Obssheet.cells(1,2).value = "Amol"
Objworkbook.Save
Objworkbook.Close
Objexcel.Quit
Set Objexcel = Nothing
Set Objworkbook = Nothing
Set Obssheet = Nothing

'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("D:\gcreddy1.xls")
objexcel.Quit

'Compare two excel files
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("D:\gcr1.xlsx")
Set objWorkbook2= objExcel.Workbooks.Open("D:\gcr2.xlsx")

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 cell.Address &" Value is different"
       Else
           msgbox cell.Address &" Value is same"
       End If
   Next

objWorkbook1.close
objWorkbook2.close
objExcel.quit
set objExcel=nothing

'Excel Paramaterization - Use excel sheet as input parameters in your script
Dim Objexcel
Set Objexcel = CreateObject("Excel.Application")
Objexcel.Visible  = True
Set Objworkbook = Objexcel.Workbooks.Open("C:\Test.xlsx")
Set Obssheet = Objworkbook.Worksheets (1)
Row_Count = Obssheet.UsedRange.Rows.Count
Msgbox Row_Count
For i =2 to Row_Count
VendorID = Obssheet.cells(i,1).value
Browser("name:=Expert Database - Search Experts").page("title:=Expert Database - Search Experts").WebEdit("html id:=ctl00_CB_tbVendorID","html tag:=INPUT").Set VendorID
Next
Objworkbook.Close
Objexcel.Quit
Set Objexcel = Nothing
Set Objworkbook = Nothing
Set Obssheet = Nothing

Comments

Popular Posts

Demystifying Automation Frameworks: A Comprehensive Guide to Building Scalable Solutions

Mastering Java Collections: Your Secret Weapon for Robust Automation Frameworks

The Singleton Pattern in Test Automation: Ensuring Consistency and Efficient Resource Management

Design Patterns in Test Automation Framework

Object-Oriented Programming Concepts (OOP)