ThisWorkbook.Close SaveAs:=false

aamir90w

New Member
Joined
Aug 1, 2017
Messages
4
Hi,
I am using Workbook1. And from Workbook1 i open Workbook2 in read only mode "workbooks.open("Workbook2"), readonly = true
because i am using workbook2 only for read purposes, i dont want to save it. but excel gives me warning to save the workbook.

I have tried to put this command in workbook2 "ThisWorkbook.Close Save:= false" in beforeclose function. But after that command exectued excel crashed!

Help please!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If you are running code from Workbook1, then that would be 'ThisWorkbook' and using the command
Code:
ThisWorkbook.Close False
Would close Workbook1, terminating your code. So Excel is not necessarily crashing, it is probably just closing the host workbook. If you used
Code:
Workbooks(2).Close False
it might work better.
 
Last edited:
Upvote 0
If you are running code from Workbook1, then that would be 'ThisWorkbook' and using the command
Code:
ThisWorkbook.Close False
Would close Workbook1, terminating your code. So Excel is not necessarily crashing, it is probably just closing the host workbook. If you used
Code:
Workbooks(2).Close False
it might work better.

No, I close workbook2 just normal way with x from top right corner, and in workbook2 i have written a code in beforeclose action "ThisWorkbook.Close false"
 
Upvote 0
Try adding this line in your before close macro, before the 'ThisWorkbook.Close False' statement.
Code:
ThisWorkbook.Saved = True
and see if that solves the problem. You basically lie to the compiler by setting the saved trigger.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top