Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Workbook is saved on close - why?

Why doesn't this line of code work:
ActiveWorkbook.Close savechanges = False

nor does this one:
Databook.Close savechanges = False
in both cases above the file gets saved even though it shouldn't

but this one works
DataBook.Close False
all variables are declared


code excerpt:
For i = 1 To 10
Workbooks.Open .Files(i)
Set DataBook = ActiveWorkbook
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
MonthStamp
Range("data").Copy
NewWkBook.Activate
ActiveSheet.Paste
Next
DataBook.Activate
Application.DisplayAlerts = False
DataBook.Close False 'this works
'ActiveWorkbook.Close savechanges = False doesn't work
NewWkBook.Activate
Next i
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Workbook is saved on close - why?

Have you tried this code instead?

ActiveWorkbook.Close SaveChanges:=False

I think you need the colon in there.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Workbook is saved on close - why?

There are two problems at work here.

ActiveWorkbook.Close savechanges = False

First, you don't have Option Explicit in your module. Therefore, VBA will
declare a variable when it encounters a variable name and give it a default
value. The second problem is that you are missing the colon in the named
argument assignment. Without the colon, VBA sees 'savechanges' as a
variable name, not a named argument, so it creates the variable and gives it
a default value of False (since it is used to compare against the boolean
value False). Therefore, your code is the same as

ActiveWorkbook.Close (False = False) doesn't work

And since 'False = False' evaluates to True, you are passing a value of True
to the first argument of Close, which causes the workbook to be saved.

All that said, you need to include the colon in the named argument
assignment:

ActiveWorkbook.Close savechanges:= False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dee Veloper" wrote in message
om...
Why doesn't this line of code work:
ActiveWorkbook.Close savechanges = False

nor does this one:
Databook.Close savechanges = False
in both cases above the file gets saved even though it shouldn't

but this one works
DataBook.Close False
all variables are declared


code excerpt:
For i = 1 To 10
Workbooks.Open .Files(i)
Set DataBook = ActiveWorkbook
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
MonthStamp
Range("data").Copy
NewWkBook.Activate
ActiveSheet.Paste
Next
DataBook.Activate
Application.DisplayAlerts = False
DataBook.Close False 'this works
'ActiveWorkbook.Close savechanges = False doesn't work
NewWkBook.Activate
Next i



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Workbook is saved on close - why?

Thanks CJ, Thanks Chip
that was a "doh" moment for me.
;)

"Chip Pearson" wrote in message ...
There are two problems at work here.

ActiveWorkbook.Close savechanges = False

First, you don't have Option Explicit in your module. Therefore, VBA will
declare a variable when it encounters a variable name and give it a default
value. The second problem is that you are missing the colon in the named
argument assignment. Without the colon, VBA sees 'savechanges' as a
variable name, not a named argument, so it creates the variable and gives it
a default value of False (since it is used to compare against the boolean
value False). Therefore, your code is the same as

ActiveWorkbook.Close (False = False) doesn't work

And since 'False = False' evaluates to True, you are passing a value of True
to the first argument of Close, which causes the workbook to be saved.

All that said, you need to include the colon in the named argument
assignment:

ActiveWorkbook.Close savechanges:= False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dee Veloper" wrote in message
om...
Why doesn't this line of code work:
ActiveWorkbook.Close savechanges = False

nor does this one:
Databook.Close savechanges = False
in both cases above the file gets saved even though it shouldn't

but this one works
DataBook.Close False
all variables are declared


code excerpt:
For i = 1 To 10
Workbooks.Open .Files(i)
Set DataBook = ActiveWorkbook
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
MonthStamp
Range("data").Copy
NewWkBook.Activate
ActiveSheet.Paste
Next
DataBook.Activate
Application.DisplayAlerts = False
DataBook.Close False 'this works
'ActiveWorkbook.Close savechanges = False doesn't work
NewWkBook.Activate
Next i

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
workbook before close mohavv Excel Discussion (Misc queries) 2 November 21st 07 01:27 AM
ex03 file saved at 9000Kb. close immediately & size goes 16000kb puzzled Excel Worksheet Functions 0 April 23rd 07 05:44 PM
Why does only one document close without asking to be saved? freyabeads Excel Discussion (Misc queries) 0 February 22nd 06 09:05 PM
How can I see a copy of a saved workbook before I saved it again? Norma Excel Worksheet Functions 2 May 11th 05 10:31 AM
Changes are saved to workbook even though I chose "No" when selecting close Steve Smallman Excel Programming 1 December 6th 03 12:21 AM


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"