Com Exception Error when Automating Excel from VB.Net

Posted on Friday 21 December 2007

UPDATE!
hueymanchew, quite rightly points out that .text is read only, so the you can’t write to that property of a cell! A case of not seeing the wood for the tree I think!

I’m writing a light wight class to use in VB.Net projects which will late bind to Excel and dump a load of data into a worksheet or two. I want to late bind to avoid having to worry about which Interop Assemblies to use. Now with liberal use of “Object” decelerations it all work ok - sort of.
One strange thing is the fact that range(x).Text throws a wobbely, but that range(x).value is ok, probably something to do with whats the default? I’ve not seen this when automating with an early bound object and a “proper” PIA.

Code:
CodeWindow.PNG

Error:
ErrorMessage.png

Anyone else seen this - know what’s going on?


2 Comments for 'Com Exception Error when Automating Excel from VB.Net'

  1.  
    hueymanchew
    22 December 2007 | 12:30 pm
     

    In Excel IDE’s object browser Text property of Range object is described as read-only, which explains IMO why it does not work for you.

  2.  
    30 March 2008 | 6:44 pm
     

    just try this

    Dim xlApp As Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim misValue As Object = System.Reflection.Missing.Value

    xlApp = New Excel.ApplicationClass
    xlWorkBook = xlApp.Workbooks.Add(misValue)
    xlWorkSheet = xlWorkBook.Sheets(”sheet1″)
    xlWorkSheet.Cells(1, 1) = “http://vb.net-informations.com”
    xlWorkSheet.SaveAs(”C:\vbexcel.xlsx”)

    xlWorkBook.Close()
    xlApp.Quit()

    i got it from

    http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm

    check it

    rbt.

Leave a comment

(required)

(required)


.

Use [VBA] Your Code [/VBA], when posting code, cheers Ross x /


RSS feed for comments on this post | TrackBack URI