I am trying to open and write to an existing Excel worksheet but I get the error "ComExecption was unhandled, Exception from HRESULT: 0x800A03EC" when I try to write to a cell.
I haven't been able to find out what this means.
Imports Excel = Microsoft.Office.Interop.Excel
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim DGV1 As DataGridView = DataGridView1
Dim app As New Excel.Application
Dim wb As Excel.Workbook = app.ActiveWorkbook
'Dim sht As Excel.Worksheet
Dim NumCols As Integer = DGV1.Columns.Count
Dim filePath As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Master.xls")
wb = app.Workbooks.Open(filePath)
app.Visible = True
'copy header names into spreadsheet.
For i As Integer = 0 To NumCols
For Each col As DataGridViewColumn In DataGridView1.Columns
wb.Sheets(1).Cells(i + 6, 0) = col.HeaderText
All the code examples that I have found seem fairly similar to my code. I'm guessing I made a simple mistake but I can't figure out where. Any and all help is welcome.