I am trying to write to an excel file, then save it as a different name (preserving the initial file as a template). However I am getting the following error:
error: Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
line : xlBook = xlApp.Workbooks.open("c:\a
Here is what I am trying to do
1) open c:\ahr\ahr_tmp.xls
2) add data from a datagridView (called resultsGrid)
3) save it as a different excel file with the date stamp.
4) I have considered using ado.net to access the file, but I cannot find any documentation on how to save the file under a different filename, just updating an existing one.
I am sure there are other problems that could be with this code, but I cannot get past that one line to find them. I have imported the excel resources needed for this project. As you might have guessed, I have never tried this before. The code for the entire sub is listed below. I have also tried using CType in creating the objects but that resulted in the same error. Any help would be appreciated.
Thanks in advance.
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim rowLoop As Integer = 0
Dim colLoop As Integer = 0
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.open("c:\ahr\ahr_tmp.xls")
xlSheet = xlBook.Worksheets(1)
Do While rowLoop < resultsNumber
colLoop = 1
Do While colLoop < 40
.Cells(rowLoop + 1, colLoop) = resultsGrid.Rows(rowLoop).Cells(colLoop).Value
colLoop = colLoop + 1
rowLoop = rowLoop + 1
Dim dateStamp As Date = Date.Now
Dim fName As String = "c:\ahr\ahr_rpt_" & dateStamp & ".xls"