I need to open an Excel-file, add a formular to the lastRow+1 in col "G" and then save it again. I tried:
Dim fso, Workbook, Sheet, lastRow, file
file="MyFile.xls"
Set fso = CreateObject("Scripting.FileSystemObject")
Set EXCEL = CreateObject("Excel.Application")
Set Workbook = EXCEL.Workbooks.Open(file)
Set Sheet = EXCEL.Application.ActiveSheet
lastRow = Sheet.Cells(Sheet.Rows.Count, 7).End(xlUp).Row -> "Unknown Runtime-error"
Range("G" + CStr(lastRow + 1)).Select
ActiveCell.Formula = "=SUM(G2:G" + CStr(lastRow) + ")"
Selection.Font.Bold = True
Workbook.SaveAs file, "56"
Workbook.close
EXCEL.quit
The code to set the formular works greate inside an VBA-Excel-Macro, but simply doesn't when using VBS: I just get an "unknown runtime error in line 8 char 3, code 800A03EC" - which doesn't really help much to figure out what might be wrong.
Any ideas how to make this work in VBS with Excel 2013?