Excel automating problem
Hello
I'm doing a project which uses the excel object. I have tried out that i can create a new excel application, get the sheet and make some change, then save it to my harddrive. I can find the new file with all the changes I made. My problem is that I have to open an exiting .xls file(because the format is required), and fill out it with new information, then save it as a new file. There is my code
Dim oExcel, oBook, oSheet As Object
Const sSampleFolder = "F:\ExcelFile\"
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open(sSampleFolder & "accounting.xls")
oSheet = oBook.Worksheets(1)
oSheet.Range("D9").Value = "The Graduate School"
oSheet.Range("D10").Value = "Lawson Accounting Unit"
oSheet.Range("D11").Value = "Setup & Upload Spreadsheet"
Dim tic, filename As String
tic = DateTime.Now.Ticks.ToString()
filename = "acctsetup" + tic + ".xls"
oBook.SaveAs(sSampleFolder & filename)
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
My problem here is that I can create the new excel file and save it with the same format(some of the fields are pre-filled), but all the changes I made are nowhere to be found
Can somebody be so kind and tell me what's wrong with my code?
Thanks in advance
Tony
|