Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET 2022 Read from Excel 1

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,494
5
38
US
With the reference to Excel, this code works OK in 2015:

Code:
Imports Microsoft.Office.Interop
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xlApp As New Excel.Application
        Dim strExcel As String = "C:\Test\TestExcel.xlsx"

        With xlApp
            .Visible = True
            .Workbooks.Open(strExcel, [ReadOnly]:=False)
            With .Workbooks(1).Worksheets(1)
                [red]Debug.Print(.cells(2, 2))[/red]
            End With
        End With
    End Sub
End Class

But in VB.NET 2022, the [red]red[/red] line of code gives me "public member cells on type worksheet not found" error.

Any example of the bare-bone code to read values from Excel in VB.NET 2022?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Code:
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Dim xlApp As New Excel.Application
       Dim strExcel As String = "D:\Downloads\DeleteMe\source.xlsx"
       Dim xlBook As Excel.Workbook
       Dim xlSheet As Excel.Worksheet
       Dim xlCells As Excel.Range

       With xlApp
           .Visible = True
           xlBook = .Workbooks.Open(strExcel, [ReadOnly]:=False)
           xlSheet = xlBook.Worksheets(1)
           xlCells = xlSheet.Cells(2, 2)
           Debug.Print(xlCells.Value)
       End With
   End Sub
 
Although the title of the post is misleading as I switched from DataGridView to simply reading an Excel file, there is a lot of information in the post about Excel files.
(Special thanks to Andrzejek)
thread1867-1828231: How to get data from DataGridView to a Listbox?
Rick Stanich
CMM Programming and Consulting, LLC
 
Rick,
I think you wanted to post your comment in thread1867-1828231

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Actually, I forgot to add the link.

Rick Stanich
CMM Programming and Consulting, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top