Can Visual Basic 2005 read and write to an excel xls file?

Can Visual Basic 2005 read and write to an excel xls file   Can it do it without an addin or is there an addin/snippet available   thanks scott

Answer this question

Can Visual Basic 2005 read and write to an excel xls file?

  • aquaseal

    Had a look at the features guide http://msdn.microsoft.com/vstudio/products/compare/default.aspx and you may be right. It seems to say that the express edition cannot Another marketing ploy You need the Tools for Office or the Team edition.


  • ibeanz

     scott71 wrote:
    Can Visual Basic 2005 read and write to an excel xls file   Can it do it without an addin or is there an addin/snippet available

    You can use ADO.NET or automation:

    http://support.microsoft.com/default.aspx scid=kb;EN-US;Q316934
    http://support.microsoft.com/default.aspx scid=kb;EN-US;Q311731
    http://support.microsoft.com/kb/q301982/

     



  • Chris Hannon

    I found this code sample in VB help. but can't seem to find it again. This code will creat a new Excel worksheet, put some data on it. Then save the work book to the specified file (.xls).

    Before this code will run you must add a reference to the to Microsoft Excel Object Library: Press Project, Add Reference, Select the COM tab and scroll to and double click on the Microsoft Excel Object Library.

    This code only writes to an Excel file. If anyone can tell me how to READ from an existing .xls I would appriciate it.

    Dim xlApp As Excel.Application

    Dim xlBook As Excel.Workbook

    Dim xlSheet As Excel.Worksheet

    Dim x As Integer

    xlApp = CType(CreateObject("Excel.Application"), Excel.Application)

    xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)

    xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

    With xlSheet.Application

    ' The following statement shows the sheet.

    .Visible = True

    ' put some data on the worksheet

    For x = 1 To 10

    .Cells(x, 1) = x

    Next x

    ' save the workbook

    xlBook.SaveAs("C:\Test.xls")

    ' close the workbook.

    .Quit()

    End With


  • Jung Yi

    What about the "Express Edition" The two links you posted seems to relate to VB6. I don't think the Visual Basic 2005 Express Edition can read and write to an Excel spreadsheet. But if someone has a sure aunswer please post here. Thanks!
  • NateLondon

    It most certainly can, has to be able to really since you script excel with VBA. Read these articles
    http://msdn.microsoft.com/library/default.asp url=/library/en-us/odc_xl2003_ta/html/odc_XLxmlhowto_.asp
    http://support.microsoft.com/default.aspx scid=kb;en-us;285891
    and download the example code.

  • 0oseven

    You can READ and make changes to excel files too!

    To continue from the last program, try this:

    Dim xlApp As Excel.Application

    Dim xlBook As Excel.Workbook

    Dim xlSheet As Excel.Worksheet

    Dim x As Integer

    xlApp = CType(CreateObject("Excel.Application"), Excel.Application)

    xlBook = CType(xlApp.Workbooks.Open("C:\Test.xls"), Excel.Workbook)

    xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

    With xlSheet.Application

    ' The following statement shows the sheet.

    .Visible = False

    ' Add data to existing worksheet

    .Cells(10, 10) = "HELLO!!!"

    ' save the workbook

    xlBook.Save()

    ' close the workbook.

    .Quit()

    End With


  • Sandeep Bhatia

    Should be able to, Just add a reference to the Microsoft Excel 9 Object Library.
  • Can Visual Basic 2005 read and write to an excel xls file?