Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Opening Excel in VB

Posted on 2002-04-26
4
Medium Priority
?
164 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
[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
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 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 143

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

Technology Partners: 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 (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

722 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