We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Private Sub btnExcelExport_Click(sender As Object, e As EventArgs) Handles btnExcelExport.Click Dim oXLApp As Excel.Application 'Declare the object variables Dim oXLBook As Excel.Workbook Dim oXLSheet As Excel.Worksheet oXLApp = New Excel.Application 'Create a new instance of Excel oXLBook = oXLApp.Workbooks.Add 'Add a new workbook oXLSheet = oXLBook.Worksheets(1) 'Work with the first worksheet oXLApp.Visible = True 'Show it to the user With oXLApp Dim Col As DataGridViewColumn Dim i As Integer = 1 For Each Col In DataGridView1.Columns .Cells(1, i).Value = Col.HeaderText i += 1 Next i = 2 Dim RowItem As DataGridViewRow Dim Cell As DataGridViewCell For Each RowItem In DataGridView1.Rows Dim j As Integer = 1 For Each Cell In RowItem.Cells .Cells(i, j).Value = Cell.Value j += 1 Next i += 1 Next End With 'oXLSheet.Range("P:P").EntireColumn.Delete() oXLSheet.UsedRange.Borders.LineStyle = 1 oXLApp.Columns.AutoFit() oXLSheet.Range("A:A").Font.Bold = True oXLBook = Nothing 'Disconnect from Excel (let the user take over) oXLApp = Nothing oXLSheet = Nothing End Sub
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|Excel 2016 - Add-In giving Error 91 Object Variable not Set when opening a New Workbook||12||35|
|Excel VBA Script||9||56|
|how to read data from all excel sheet and copy it in in Master sheet||2||24|
|How to turn this IF statement into a UDF?||5||17|
Join the community of 500,000 technology professionals and ask your questions.