Solved

Importing Excel Files into Visual Basic 2008

Posted on 2008-06-25
3
1,543 Views
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. :-)
0
Comment
Question by:ZoeticNepenthe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:JonMny
ID: 21866239
0
 
LVL 1

Author Comment

by:ZoeticNepenthe
ID: 21866516
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

0
 
LVL 1

Accepted Solution

by:
ZoeticNepenthe earned 0 total points
ID: 21883817
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
 
wb.Close()
 
xlApp.Quit()
 
ws = Nothing
wb = Nothing
xlApp = Nothing

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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