ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with Activeworkbook.Close SaveChanges:=False (https://www.excelbanter.com/excel-programming/368680-problem-activeworkbook-close-savechanges-%3Dfalse.html)

Ron McCormick

Problem with Activeworkbook.Close SaveChanges:=False
 
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

Tom Ogilvy

Problem with Activeworkbook.Close SaveChanges:=False
 
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.

--
Regards,
Tom Ogilvy


"Ron McCormick" wrote:

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


Ron McCormick

Problem with Activeworkbook.Close SaveChanges:=False
 
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

"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"Ron McCormick" wrote:

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


NickHK

Problem with Activeworkbook.Close SaveChanges:=False
 
Does this work as expected ?
TownT.Close SaveChanges:=False

Any extra code in the _BeforeClose events ?

NickHK

"Ron McCormick" wrote in message
...
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

"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"Ron McCormick" wrote:

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




Ron McCormick

Problem with Activeworkbook.Close SaveChanges:=False
 
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

"NickHK" wrote:

Does this work as expected ?
TownT.Close SaveChanges:=False

Any extra code in the _BeforeClose events ?

NickHK

"Ron McCormick" wrote in message
...
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

"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy


"Ron McCormick" wrote:

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






All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com