• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Reading Excel Spreadsheets with Visual Basic 6

I'd like to be able to read information out of an Excel worksheet using Visual Basic 6.  Does anyone have any sample code that allows me to do this without buying a 3rd party package.  Also writing information to a new spreadsheet would be helpful.

Thanks
0
facole
Asked:
facole
1 Solution
 
jimbobmcgeeCommented:
You wish to access an Excel worksheet from VB?  Do you wish to do it without ever having installed Excel?

If not, you can use the Excel classes, installed when Excel is installed, as follows:

      Dim oExcel, oWorkbook, oSheet, oNewSheet

      Set oExcel = CreateObject("Excel.Application")
      Set oWorkbook = oExcel.Workbooks.Open("x:\path\file.xls")
      Set oSheet =oWorkBook.Sheets("mysheetname")

      MsgBox "The content of cell B3 is: " & oSheet.Range("B3").Value

      Set oNewSheet = oWorkbook.Sheets.Add

      oNewSheet.Range("A1").Value = "This is a new sheet"

      oWorkbook.Save
      oExcel.Quit

      Set oNewSheet = Nothing
      Set oSheet = Nothing
      Set oWorkbook = Nothing
      Set oExcel = Nothing

if you want Excel functionality, without Excel, and have spare $1000, you could try Aspose (http://www.aspose.com)...

HTH

J.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now