VBScript to open excel spreadsheet, update cell, save then close - TechRepublic
Question
April 9, 2008 at 06:06 PM
mail.aaron.kirk

VBScript to open excel spreadsheet, update cell, save then close

by mail.aaron.kirk . Updated 13 years ago

Hi all,

I’m trying to write a script that will open an excel spreadsheet, update a cell, save the spreadsheet and then close it.

I get the following error when I run the script:
Wrong number of arguments or invalid property assignment: ‘objExcel.ActiveWorkbook.Save’
Line 8, Code: 800A01C2

I have noticed that it has opened Excel but there are 2 spreadsheets running: test.xls and book1

Here is the code I have:

————————————-
Set objExcel = CreateObject(“Excel.Application”)
Set objWorkbook = objExcel.Workbooks.Open(“C:\test.xls”)

objExcel.Application.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = “Test value”

objExcel.ActiveWorkbook.Save “C:\test.xls”
objExcel.ActiveWorkbook.Close

objExcel.Application.Quit
WScript.Echo “Finished.”
WScript.Quit
————————————-

Any assistance would be greatly appreciated thank you.

Regards,
Aaron.

This discussion is locked

All Comments