Friday, April 2, 2010

VBScript - Inserting a Formula into an Excel Spreadsheet

VBScript - Inserting a Formula into an Excel Spreadsheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

objExcel.Cells(1, 1).Value = 11
objExcel.Cells(2, 1).Value = 54
objExcel.Cells(3, 1).Value = 32
objExcel.Cells(4, 1).Value = 55

objExcel.Cells(6, 1).Formula = "=SUM(A1:A4)"
objExcel.Cells(7, 1).Formula = "=MIN(A1:A4)"
objExcel.Cells(8, 1).Formula = "=MAX(A1:A4)"
objExcel.Cells(9, 1).Formula = "=AVERAGE(A1:A4)"

[Via]