Click here to Skip to main content
15,884,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Using Visual Basic - need to access a Excel workbook Cell

Programed VB since the early days, and had every thing working great in win 10 VB. Then had to upgrade to Visual Studio 2002, when i upgraded to Win 11

looking for just the code to access one cell on a excel Office 365 workbook...

thanks for the help

What I have tried:

Using Visual Basic - need to access a Excel workbook Cell

Programed VB since the early days, and had every thing working great in win 10 VB. Then had to upgrade to Visual Studio 2002, when i upgraded to Win 11

looking for just the code to access one cell on a excel Office 365 workbook... 

thanks for the help
Posted
Updated 24-Feb-22 9:41am
Comments
Maciej Los 24-Feb-22 12:41pm    
VB or VB.NET? It really matters.

If you want to access single cell in worksheet, you can use ADO.NET[^] - OleDB[^].

Usage:
VB.NET
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=FullFileName.xlsx;Extended Properties='Excel 12.0;HDR=YES';"
Using connection As New OleDbConnection(connectionString)
      Using command As New OleDbCommand(selectSQL)
          command.Connection = connection
          Try
        connection.Open()
        Dim singleValue = command.ExecuteScalar()
        'you can use singleValue variable now ;)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Using
End Using


For further details, see:
Obtaining a Single Value from a Database - ADO.NET | Microsoft Docs[^]
Retrieving Data Using a DataReader - ADO.NET | Microsoft Docs[^]

Or...
You can use EPPlus[^] NuGet package. See: How to Use EPPlus in VB[^]
 
Share this answer
 
VB (4-6) is basically VBA in todays world. You really need to update your app as it has died a long time ago and forms part of legends out there.

You also need to start thinking about going to .NET as your clients will also upgrade soon to WIN 11 and that means that all your code will crash, unless this is an app made for you many a year ago.

That being said, can you access the excel file?, is the code in VBA makro or VB4,5,6?, what error message do you get, what version of excel? etc etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900