Print the contents of an Excel spreadsheet (VBScript)

This code can be found in Chapter 1 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0

' ------ SCRIPT CONFIGURATION ------
strExcelPath = "d:\data.xls"
intStartRow = 2
' ------ END CONFIGURATION ---------
On Error Resume Next
set objExcel = CreateObject("Excel.Application")
if Err.Number <> 0 then
	Wscript.Echo "Excel application not installed."
	Wscript.Quit
end if
On Error GoTo 0
objExcel.WorkBooks.Open strExcelPath
set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
intRow = intStartRow
do while objSheet.Cells(intRow, 1).Value <> ""
	WScript.Echo "Row " & intRow
	WScript.Echo "Cell 1: " & objSheet.Cells(intRow, 1).Value
	WScript.Echo "Cell 2: " & objSheet.Cells(intRow, 2).Value
	WScript.Echo "Cell 3: " & objSheet.Cells(intRow, 3).Value
	WScript.Echo "Cell 4: " & objSheet.Cells(intRow, 4).Value
	intRow = intRow + 1
	WScript.Echo
loop
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
Wscript.Echo "Done"

This code has been viewed 2692 times.

New from the creators of TechTasks.com: StatSheet.com