Solved

Destroying Excell  (objects)

Posted on 2002-06-20
5
327 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

16 Experts available now in Live!

Get 1:1 Help Now