Importing Excel Files into Visual Basic 2008

Posted on 2008-06-25
Last Modified: 2008-09-30
I am looking for a simple way to import an Excel file into VB 08 so that I can extract cells, like E/15 ,or groups of cells, like B/1 to B/10 or A/1 to H/1, and assign them to a variable or list. It would be great if someone could provide me with an example code to do this. :-)
Question by:ZoeticNepenthe
  • 2

Expert Comment

Comment Utility

Author Comment

Comment Utility
I have a code (attached to this post) from an older version of VB that lets you import a Excel file and pull out the cell you want as long as you know the place of the cell like A/1. The problem with the code is that it no longer works in VB 08. Something like this would be great because its simple and easy to use. In the end I dont know how many Excel files I will have to import but I know I will have about 30 variables that will need to be updated every minute from the Excel file, which is why I want to keep it simple. :-)
'Import Microsoft Excel Library

    Dim objXLApp As Excel.Application

    Dim intLoopCounter As Integer


    Set objXLApp = New Excel.Application


    With objXLApp

        .Workbooks.Open "C:\File.xls"



        For intLoopCounter = 1 To 10

            List1.AddItem .Range("A" & intLoopCounter)

        Next intLoopCounter


        .Workbooks(1).Close False


    End With


    Set objXLApp = Nothing

Open in new window


Accepted Solution

ZoeticNepenthe earned 0 total points
Comment Utility
Figured it out...
Dim xlApp As Microsoft.Office.Interop.Excel.Application

Dim wb As Microsoft.Office.Interop.Excel.Workbook

Dim ws As Microsoft.Office.Interop.Excel.Worksheet

xlApp = (New Microsoft.Office.Interop.Excel.Application)

wb = xlApp.Workbooks.Open("PATH TO FILE")

ws = wb.Worksheets("worksheet")

TextBox1.Text = ws.Cells(5, 4).Value



ws = Nothing

wb = Nothing

xlApp = Nothing

Open in new window


Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now