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
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