Solved

Opening Excel in VB

Posted on 2002-04-26
4
155 Views
Last Modified: 2010-05-02
I'm am running a program that has to access Excel worksheets to read data, but after I close the program, I have a lot of instances of Excel still running.  I have added the code to close Excel

Worksheets.Close
Workbooks.Close

but it still doesn't.

Any help please???
0
Comment
Question by:Cosmo439
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6971160


dim xlsApp as object
dim xlsBook as object
dim xlsSheet as object

set xlsApp = CreateObject ("Excel.Application")
set xlsBook = xlsApp.Workbooks.Open (yourfile)
set xlsSheet = xlsBook.Sheets(yoursheet)

<etc>

set xlsSHeet = nothing
xlsBook.Close
set xlsBook = nothing
xlsApp.Quit
set xlsApp = nothing

Cheers

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6971210
I am with you angelIII,
but why using object type var instead of strong typed one setting a reference to Microsoft Excel library?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6971249
Using the AS OBJECT, you can work with "any" version of Excel installed. I prefer this in my projects even if the early binding has performance benefits and developing ease...
My code will run even if Office XP is installed while i developed on Office 2000

CHeers
0
 

Author Comment

by:Cosmo439
ID: 6971655
Thanks for the help, that's been driving me crazy for a while now.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

785 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