README.md

December 4, 2022 ยท View on GitHub

Display Excel Spreadsheet Cell Data

Description

This code snippet shows how to take an existing Excel 2000 document and display the cell data from different worksheets. This may work with other versions of Excel

More Info

The following COM references are required:

Microsoft Excel 9.0 Object Library

Microsoft Office 9.0 Object Library

Submitted On
ByLloyd Christmas
LevelBeginner
User Rating4.7 (14 globes from 3 users)
CompatibilityVB.NET
CategoryDocuments/ Frames
World.Net (C#, VB.net)
Archive File

Source Code

'Open an Excel document, get a value from 3 cells, all on different worksheets
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet1 As Excel._Worksheet
    Dim xlSheet2 As Excel._Worksheet
    Dim xlSheet3 As Excel._Worksheet
    Dim mytext1 As String
    Dim mytext2 As String
    Dim mytext3 As String
    xlApp = CreateObject("Excel.Application")
    xlBook = xlApp.Workbooks.Open("c:\test.xls")
    xlSheet1 = xlBook.Worksheets(1)
    xlSheet2 = xlBook.Worksheets(2)
    xlSheet3 = xlBook.Worksheets(3)
    mytext1 = xlSheet1.Range("A1").Value
    mytext2 = xlSheet2.Range("A9").Value
    mytext3 = xlSheet3.Range("C1").Value
    MessageBox.Show(mytext1 + " " + mytext2 + " " + mytext3)
    xlBook.Close()