Solved

Opening Excel in VB

Posted on 2002-04-26
4
162 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 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…

734 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