Solved

Opening Excel in VB

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now