Problem with Activeworkbook.Close SaveChanges:=False

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

Guest

I have a model that opens files, copies data from the file opened, and is
supposed then to close the file with: Activeworkbook.Close
SaveChanges:=False. It has worked satisfactorily for years but seems to have
stopped working recently, following an update of the files from which the
data is extracted. Any ideas why this might be happening?

TIA

Ron
 
My guess would be that the file that seems to fail is not the activeworkbook
when the code is run.

Other than that, I have never seen a problem with that command.
 
Tom,

Thanks for your reponse.

Your guess seems like it should be the source of the problem, but on
"looking" at what happens when I run the code it appears that the right
workbook is active.

Early in the process the file from which the data is copied is set as
"TownT" with the following code.

Set TownT = Workbooks.Open(FileName:=ThisWorkbook.Path & "\" & CentreName)
'opens file from centre name list

The code leading up to where the procedure crashes is:

TownT.Activate
Application.EnableEvents = True
ActiveWorkbook.Close SaveChanges:=False

And whenever the code runs the TownT file does appear to be active. This
appears to be confrimed in that when you end the process the relevant file
does close with out saving. The error message that I'm getting is "Error '9'
: Subscript out of range".

Any further help woiuld be appreciated.

Thanks again,
Ron
 
Does this work as expected ?
TownT.Close SaveChanges:=False

Any extra code in the _BeforeClose events ?

NickHK
 
Thanks Nick,

You're a star. I'd forgotten about the workbook BeforeClose event, as one
of the sheet names had changed in the file from which the data is taken, but
the Workbook_BeforeClose event had not been changed to reflect that.

Credit too to Tom who rightly pointed out that the problem was (likely) in
the file to be closed.

Many thanks,
Ron
 

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