Solved

Opening Excel in VB

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Computer crashes, following error message in event manager 5 280
message box in access 4 52
Sub or Function is not defined 6 54
Problem to line 23 74
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
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…

730 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