-1

What is wrong in these codes, it do nothing
Please help

Dim oExcel As Object
        Dim oBook As Object
        Dim osheet As Object
        oExcel = CreateObject("Excel.Application")
        oBook = oExcel.Workbooks.Add
        osheet = oBook.sheets("sheet1")

        'Paste the data.
        Dim j As Integer
        For i = 0 To DataGridView1.RowCount - 2
            For j = 0 To DataGridView1.ColumnCount - 1
                oBook.Cells(i + 1, j + 1) = DataGridView1(j, i).Value.ToString()
            Next
        Next

        'Save the workbook and quit Excel.
        oBook.SaveAs("c:\Book5.xls")
        oBook = Nothing
        oExcel.Quit()
        oExcel = Nothing
        GC.Collect()
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by tqmd1
0

I think you should have ActiveSheet in the assignment line (12)

ExcelSheetFO.ActiveSheet.Cells(2, i) = "Some value"
0

I think you should have ActiveSheet in the assignment line (12)


I added this line

ExcelSheetFO.ActiveSheet.Cells(2, i) = "Some value"

But it still not work

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.