Link to home
Start Free TrialLog in
Avatar of Member_4228183
Member_4228183

asked on

Importing Excel Files into Visual Basic 2008

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. :-)
Avatar of JonMny
JonMny

Avatar of Member_4228183

ASKER

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"
        .Workbooks(1).Worksheets(1).Select
    
        For intLoopCounter = 1 To 10
            List1.AddItem .Range("A" & intLoopCounter)
        Next intLoopCounter
        
        .Workbooks(1).Close False
        .Quit
    End With
    
    Set objXLApp = Nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_4228183
Member_4228183

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial