Exception from HRESULT: 0x800A03EC
Hi friend plz help me
i m putting data from a dataset to an excel file in windows application.
after setting value of 2 cells
i m getting this error : Exception from HRESULT: 0x800A03EC
the code is
Dim MyExcel As New Microsoft.Office.Interop.Excel.Application
Try
MyExcel.Workbooks.Open(Application.StartupPath() & "\Preview\WorkSheet1.xls")
Catch ex As Exception
MsgBox("Open : " & ex.Message)
MyExcel = Nothing
End Try
MyExcel.ActiveWorkbook.ActiveSheet.Cells(5, 1) = ("Party Ledger for Party " & ds.Tables(0).Rows(0).Item("PartyName"))
MyExcel.ActiveWorkbook.ActiveSheet.Cells(6, 1) = ("From " & CDate(ds.Tables(0).Rows(0).Item("Date")).Date & " To " & CDate(ds.Tables(0).Rows(ds.Tables(0).Rows.Count - 1).Item("Date")).Date)
Dim rows As Integer = 8
Dim TotalDr As Decimal = 0
Dim TotalCr As Decimal = 0
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 0) = i + 1
' getting error here
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 1) = ds.Tables(0).Rows(i).Item("Description")
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 2) = ds.Tables(0).Rows(i).Item("Date")
If ds.Tables(0).Rows(i).Item("Type") = "Sales" Or ds.Tables(0).Rows(i).Item("Type") = "Issue" Then
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 3) = CDbl(ds.Tables(0).Rows(i).Item("Ammount"))
TotalDr = totaldr + CDbl(ds.Tables(0).Rows(i).Item("Ammount"))
Else
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 3) = ""
End If
If ds.Tables(0).Rows(i).Item("Type") = "Purchase" Or ds.Tables(0).Rows(i).Item("Type") = "Receive" Then
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 4) = CDbl(ds.Tables(0).Rows(i).Item("Ammount"))
TotalCr = TotalCr + CDbl(ds.Tables(0).Rows(i).Item("Ammount"))
Else
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 4) = ""
End If
If ds.Tables(0).Rows(i).Item("ClosingBalance") < 0 Then
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 5) = ds.Tables(0).Rows(i).Item("ClosingBalance") & " Cr"
ElseIf ds.Tables(0).Rows(i).Item("ClosingBalance") > 0 Then
MyExcel.ActiveWorkbook.ActiveSheet.Cells(8 + i, 5) = ds.Tables(0).Rows(i).Item("ClosingBalance") & " Dr"
End If
rows = rows + i
Next
Dim fpath As String
Try
fpath = Application.StartupPath() & "WorkSheet1" & Date.Today.Day * Date.Today.Second & "" & ds.Tables(0).Rows(0).Item("PartyName") & ".xls"
MyExcel.ActiveWorkbook.SaveAs(fpath)
MsgBox("File Saved successfully")
Catch ex As Exception
MsgBox("Problem occur during saving report, Please Try Again.")
MyExcel = Nothing
Finally
MyExcel.ActiveWorkbook.Close(False, Application.StartupPath() & "\Preview\SuccessRateByPayer.xls")
MyExcel.DisplayAlerts = False
MyExcel = Nothing
End Try
End Sub
|