Exception from HRESULT: 0x800A03EC Error

A

Avins

Hi I have done with some stuff for sending data to excel here the code goes

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim xlApp As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim LastRow As Long


xlWorkBook = xlApp.Workbooks.Open("C:\Test.xls")
xlWorkSheet = xlWorkBook.Worksheets("Sheet1")
'display the cells value B2
MsgBox(xlWorkSheet.Cells(2, 2).value)
'edit the cell with new value
xlWorkSheet.Cells(24, 9) = "3246413451324525 453165 454 684646
498465498465498465 49546 498468 4"
LastRow = xlWorkSheet.Range(24, 9).End(XlDirection.xlUp).Row
xlWorkSheet.Range("D4" & LastRow).EntireRow.AutoFit()
xlWorkBook.Save()
xlWorkBook.Close()
xlApp.Quit()

releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)

End sub


Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub

and Error comes in this line

and i wrote that to Auto fit only particular Cell ... If i use Auto fit
column then excel looks odd as what i made .. i want to make only particular
cell Autofit so i used below and in this line the error comes

LastRow = xlWorkSheet.Range(24, 9).End(XlDirection.xlUp).Row

please help me out in this

Regards
Avinash desai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top