Copy worksheet in ACCESS Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From my Access 2000 application I am opening an Excel workbook which starts
with 10 worksheets (used for other purposes). The second sheet is used to
display projects. I am adding(appending) additional worksheets as needed
depending on the number of projects encountered in my Access table.

The code runs fine, the first time, but when I run it a second time, I get
an error: "Application defined or Object defined error". If I close the
access database and open it again, the code will run the first time I click
on the button which runs the code, but errors out the second time I try to
run it. Can anyone help?? Here is the pertinent part of my code (I've
editted it to remove extraneous code that checks for every 10 projects) The
error occurs on the .sheets(2)copy...etc line :

Set appXl = GetObject("Excel.Application")
With appXl
Set objWkb = .Workbooks.Open(lstrTempWkbName)
.Sheets(2).Copy after:=Sheets(10) '*This is the line that errors
..... here I do the display of project information
.Workbooks.Close
End With

Close_Out:
appXl.Quit
Set appXl = Nothing
 
I don't see anything obvious, but I do notice you don't destroy the objWkb
object. See code added below:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top