By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Export Vb.net Datagridview to Microsoft Excel 2013

P: 54
Please I'm using vb.net 2013 and Microsoft office 2013. The below code is able to display the datagridview

into excel 2007. But the code does not display onto excel 2013 and no error gets reported. I suspect the

excel 2013 format could be the cause but i do not know how to go about it. Please help me out. Thanks, Ben

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ExcelApp As Object, ExcelBook As Object
  3.         Dim ExcelSheet As Object
  4.         Dim i As Integer
  5.         Dim j As Integer
  6.  
  7.         'create object of excel
  8.         ExcelApp = CreateObject("Excel.Application")
  9.         ExcelBook = ExcelApp.WorkBooks.Add
  10.         ExcelSheet = ExcelBook.WorkSheets(1)
  11.  
  12.         With ExcelSheet
  13.             For i = 1 To Me.DataGridViewGCL.RowCount
  14.                 .cells(i, 1) = Me.DataGridViewGCL.Rows(i - 1).Cells("GclNo").Value
  15.                 For j = 1 To DataGridViewGCL.Columns.Count - 1
  16.                     .cells(i, j + 1) = DataGridViewGCL.Rows(i - 1).Cells(j).Value
  17.                 Next
  18.             Next
  19.         End With
  20.  
  21.         ExcelApp.Visible = True
  22.         '
  23.         ExcelSheet = Nothing
  24.         ExcelBook = Nothing
  25.         ExcelApp = Nothing
  26.  
  27.  
Aug 24 '15 #1
Share this Question
Share on Google+
1 Reply


P: 24
Have you stepped through the code at all? Does it fail at a certain place?
Sep 30 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.