Link to home
Start Free TrialLog in
Avatar of capkirkie
capkirkie

asked on

Destroying Excell (objects)

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
ASKER CERTIFIED SOLUTION
Avatar of wesleystewart
wesleystewart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of capkirkie
capkirkie

ASKER

Thanks Wesley but it doesn't work for me
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
that was stupid the Excel app has to declared in code like

Set ExAp = Createobejct("Excel.Application")
darn last post

Set ExAp = Createobject("Excel.Application")