Solved

Destroying Excell  (objects)

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

717 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