Solved

Destroying Excell  (objects)

Posted on 2002-06-20
5
334 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
[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
  • 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

733 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