JohnnyBGoode
Programmer
How can i read from a excel spreadsheet (ie. workbook.xls) in VBScript?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Set fso = CreateObject("Scripting.FileSystemObject")
FileLoc = NetPath & FormFiles & "spreadsheet.xls"
' Checks to see if Excel is running - creates object
If fso.FileExists(FileLoc) Then
On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Err.Clear
Set oExcel = CreateObject("Excel.Application")
End If
Else
strErr = FileLoc & " could not be found."
MsgBox (strErr), vbCritical, "Error: File Not Found"
Exit Function
End If
' Opens desired spreadsheet
Set oWrkBook = oExcel.Workbooks.Open (FileLoc)
' Search each row for either blank(new) row or matching value
varRow = 1
Do While oExcel.Worksheets("Current Year").Cells(varRow, 1) > ""
If oExcel.Worksheets("Current Year").Cells(varRow, 1) = varVariable Then
Exit Do
End If
varRow = varRow + 1
Loop
' Add values to spreadsheet.
oExcel.Worksheets("Current Year").Cells(varRow, 1).Value = txtVar1
oExcel.Worksheets("Current Year").Cells(varRow, 2).Value = varVar2
oExcel.Worksheets("Current Year").Cells(varRow, 3).Value = txtVar3
oExcel.Worksheets("Current Year").Cells(varRow, 4).Value = txtVar4
oExcel.Worksheets("Current Year").Cells(varRow, 5).Value = txtVar5
oExcel.Worksheets("Current Year").Cells(varRow, 6).Value = txtVar6