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.
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 Next Next End Sub
From novice to tech pro — start learning today.