Friday, November 19, 2010

VBScript Code - Reading values from excel

Write the below code in a notepad and save it as a .vbs file. Either run it from command prompt or run it by double-clicking on it.

VBScript Code - Reading values from excel

Name     Salary
A        100
B        200
C        300


Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Book1.xlsx")

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""
 msgbox "Name: " & objExcel.Cells(intRow, 1).Value
 msgbox "Salary: " & objExcel.Cells(intRow, 2).Value
 intRow = intRow + 1
Loop

objExcel.Quit