Solved

Destroying Excell  (objects)

Posted on 2002-06-20
5
328 Views
Last Modified: 2009-07-29
From a Acces2000 module I want to manipulate a excell sheet in a new instance of excell. When I run the code below an instance of excell seems to be persisting in memory(my taskmanager says so). When I push the stop button in my code window its gone, althoug my code has finished executing earlier. Running the code twice without using the stop button or exiting the application althogeter I get an error 1004 on line:
ExSH.Copy after:=Worksheets("sheet1")




Public sub Start
Dim iDoc As clsDoc
Dim iRegel As clsRegel
Dim ExAp As Excel.Application
Dim ExWB As Excel.Workbook
Dim ExSH As Excel.Worksheet
Dim iTeller As Integer

Set ExAp = New Excel.Application
ExAp.Visible = True

iTeller = 1

Set ExWB = ExAp.Workbooks.Open("C:\stan\uitslag\uitdocschoon2.xls")

ExAp.AlertBeforeOverwriting = False
ExAp.DisplayAlerts = False
For Each iDoc In Sale.Docus
    Set ExSH = ExWB.Worksheets("sheet1")
    ExSH.Copy after:=Worksheets("sheet1")
    Set ExSH = ExWB.Sheets(2)
    'Sub vullen takes a byRef excell.worksheet parameter
    iDoc.Vullen ExSH
    ExSH.Name = iDoc.TruckID
    Set ExSH = Nothing
    iTeller = iTeller + 1
Next
Set ExSH = Nothing
ExWB.Worksheets("Sheet1").Delete
ExWB.SaveAs "C:\Stan\uitslag"
ExWB.Close
Set ExWB = Nothing
ExAp.Quit
Set ExAp = Nothing
End sub
0
Comment
Question by:capkirkie
  • 3
5 Comments
 
LVL 4

Accepted Solution

by:
wesleystewart earned 100 total points
ID: 7095626
I believe you need to specifically refer to Excel's application object.  I had trouble with this as well and fixed it like this:

ExAp.Application.Quit

Seems a little redundant, but it was in the object browser and seems to do the trick.

Wes
0
 

Author Comment

by:capkirkie
ID: 7096000
Thanks Wesley but it doesn't work for me
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7097070
hi Capkirkie,

try to do this

Dim ExAp As Object
Dim ExWB As Objecty
Dim ExSH As Object

Set ExAp = New Excel.Application
ExAp.Visible = True

etc........

what happens in that other code is the early binding to obejcts in the dim declaration statement

that's the first object

then you got the objects redeclared by the set lines and that's late binding

it seems then to the system that you got two excel apps running you cclean up the second but the first is still alive

hope this works for you

HAGD:O)Bruintje
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7097072
that was stupid the Excel app has to declared in code like

Set ExAp = Createobejct("Excel.Application")
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7097074
darn last post

Set ExAp = Createobject("Excel.Application")
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

911 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

21 Experts available now in Live!

Get 1:1 Help Now