ActiveWorkbook.close problem

S

Spike

Grateful for any advice on an ActiveWorkbook.close problem.

I am running a macro that opens each excel file in a folder in turn. The
macro then calls another macro that deletes the links on a worksheet in that
file, then it runs a function that calculates averages using data on that
worksheet and plugs resulting data into cells on that worksheet, then various
items of data are uploaded to a new Access database. The focus then returns
to the original macro that then closes the workbook; using
Activeworkbook.close savechanges:=false

Everytime it stops at this point and shows the standard Microsoft runtime
error 1004. If I click on debug button on that message the file then closes?
I have tried hard coding the filename and it still produces the same error.

If I comment out the delete links part of the macro it works fine, which to
me indicates that the problem is connected with deleting the links. Does
anyone have any ideas what could be causing this error.
 
J

Joel

Don't use activeworkbook. Instead set a variable to the workbook when you
open it

Set bk = workbooks.open(filename:="book1.xls")

'you code here

bk.close savechanges:=false
 
S

Spike

Thanks, yes i have tried setting a variable to hold the workbook name and
close that variable which produces the same error
 
J

Joel

My guess is the file has already been closed. I would need to see the code.
One thing you may try is to step thought the code using F8. I would set a
watch on the object as you step though the code and see which instruction
cuases the watch item to be set to nothing.

for this instruction
Set bk = workbooks.open(filename:="book1.xls")

Highlight bk with mouse. then right click hihglighted variable bk and
select ADD WATCH. The when above instruction is executed you can see the
variable bk and see when the object is no longer contains any information.
 
S

Spike

Thank you all for your help. It appers that the workbook/s the macro is
opening are very heavily locked down, have made the necessary alterations and
now works fine.
 

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

Top