<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: BeforeClose vs. BeforeReallyClose</title>
	<atom:link href="http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/</link>
	<description>Daily posts of Excel tips…and other stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 23:42:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: William</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-46123</link>
		<dc:creator>William</dc:creator>
		<pubDate>Fri, 14 May 2010 18:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-46123</guid>
		<description>&lt;p&gt;This is great, except for when the file being saved is a large file being uploaded to a server.  In this case, it might be a good idea to push the checkifclosed sub out a bit.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>This is great, except for when the file being saved is a large file being uploaded to a server.  In this case, it might be a good idea to push the checkifclosed sub out a bit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-42009</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Sat, 07 Nov 2009 05:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-42009</guid>
		<description>&lt;p&gt;Thank you for this clever and useful workaround. It is annoying that it is necessary, BeforeClose should mean that. I found that with multiple workbooks open I needed to add Application.Quit in the BeforeClose sub, otherwise I had to close Excel twice.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thank you for this clever and useful workaround. It is annoying that it is necessary, BeforeClose should mean that. I found that with multiple workbooks open I needed to add Application.Quit in the BeforeClose sub, otherwise I had to close Excel twice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-31035</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Fri, 29 Feb 2008 23:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-31035</guid>
		<description>&lt;p&gt;I&#039;m glad this came up, because this is something I&#039;ve wanted to do.  And now that I&#039;ve done it (Dick&#039;s codeno surprise hereworks) I find that I don&#039;t quite understand it.&lt;/p&gt;
&lt;p&gt;I&#039;m staring at the &quot;Save changes&quot; query.  I take that to mean (after some experimentation) that Workbook_BeforeClose has run. And that Dick&#039;s one second delay has timed out.  So both Workbook_Deactivate and CheckifClosed are pending.  Since the code does work, that means Workbook_Deactivate has to go next if I choose anything but Cancel.  Why??  Well, because, of course.  Where is the pecking order of macros highlighted?  Checking Chip Pearson&#039;s Event Sequence, standard module macros (or at least Auto_close does) run before Workbook_deactivate, meaning CheckifClosed should do its thing (which as I said, it doesn&#039;t).&lt;/p&gt;
&lt;p&gt;Can anybody help me fully understand the flow when Cancel isn&#039;t the choice?  Thanks.&lt;/p&gt;
&lt;p&gt;...Michael&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m glad this came up, because this is something I&#8217;ve wanted to do.  And now that I&#8217;ve done it (Dick&#8217;s codeno surprise hereworks) I find that I don&#8217;t quite understand it.</p>
<p>I&#8217;m staring at the &#8220;Save changes&#8221; query.  I take that to mean (after some experimentation) that Workbook_BeforeClose has run. And that Dick&#8217;s one second delay has timed out.  So both Workbook_Deactivate and CheckifClosed are pending.  Since the code does work, that means Workbook_Deactivate has to go next if I choose anything but Cancel.  Why??  Well, because, of course.  Where is the pecking order of macros highlighted?  Checking Chip Pearson&#8217;s Event Sequence, standard module macros (or at least Auto_close does) run before Workbook_deactivate, meaning CheckifClosed should do its thing (which as I said, it doesn&#8217;t).</p>
<p>Can anybody help me fully understand the flow when Cancel isn&#8217;t the choice?  Thanks.</p>
<p>&#8230;Michael</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alison</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-30966</link>
		<dc:creator>Alison</dc:creator>
		<pubDate>Wed, 27 Feb 2008 17:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-30966</guid>
		<description>&lt;p&gt;You can release the locks before close using the following subs that I wrote: UnprotectSh and Unlocks_All in your Workbook_BeforeClose&lt;/p&gt;
&lt;p&gt;Sub UnprotectSh()&lt;br&gt;
&#039;make sure only one sheet is selected before running this sub or it fails&lt;br&gt;
Sheets(&quot;insert the name of one of your sheets here...&quot;).Select&lt;/p&gt;
&lt;p&gt;Dim sheetCount As Integer&lt;br&gt;
Dim i As Integer&lt;/p&gt;
&lt;p&gt;&#039;count how many sheets there are in the workbook&lt;br&gt;
sheetCount = Worksheets.Count&lt;/p&gt;
&lt;p&gt;&#039;unprotect each sheet number until the sheetCount is reached&lt;br&gt;
For i = 1 To sheetCount&lt;br&gt;
    Sheets(i).Unprotect&lt;br&gt;
Next i&lt;/p&gt;
&lt;p&gt;End Sub&lt;/p&gt;
&lt;p&gt;Sub Unlocks_All()&lt;/p&gt;
&lt;p&gt;&#039; Unlocks everything, be careful using this..&lt;br&gt;
&#039; You must run the UnprotectSh sub first so that all of the sheets can be selected&lt;/p&gt;
&lt;p&gt;&#039;select every cell on every sheet and substitute these sheet names with yours,&lt;br&gt;
&#039;recording a macro and selecting all of the sheets is the easiest way..&lt;br&gt;
    Sheets(Array(&quot;Year to Date Summary&quot;, &quot;January&quot;, &quot;February&quot;, &quot;March&quot;, &quot;April&quot;, &quot;May&quot;, _&lt;br&gt;
    &quot;June&quot;, &quot;July&quot;, &quot;August&quot;, &quot;September&quot;, &quot;October&quot;, &quot;November&quot;, &quot;December&quot;)).Select&lt;br&gt;
    Sheets(&quot;Year to Date Summary&quot;).Activate&lt;br&gt;
    Cells.Select&lt;br&gt;
    Range(&quot;A1?).Activate&lt;/p&gt;
&lt;p&gt;    &#039;unlocks the selected cells and ensure that formulas *can* be seen&lt;br&gt;
    Selection.Locked = False&lt;br&gt;
    Selection.FormulaHidden = False&lt;/p&gt;
&lt;p&gt;    &#039;select only one cell so that it&#039;s neater, again, substitute your values&lt;br&gt;
    Sheets(&quot;Year to Date Summary&quot;).Select&lt;br&gt;
    Range(&quot;A1?).Select&lt;/p&gt;
&lt;p&gt;End Sub&lt;/p&gt;
&lt;p&gt;Remember to lock everything down again when on Workbook_Open, I use a Locks_All and ProtectSh in that order and they&#039;re basically the reverse of the unlock and unprotect.  Good luck!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You can release the locks before close using the following subs that I wrote: UnprotectSh and Unlocks_All in your Workbook_BeforeClose</p>
<p>Sub UnprotectSh()<br />
&#8216;make sure only one sheet is selected before running this sub or it fails<br />
Sheets(&#8220;insert the name of one of your sheets here&#8230;&#8221;).Select</p>
<p>Dim sheetCount As Integer<br />
Dim i As Integer</p>
<p>&#8216;count how many sheets there are in the workbook<br />
sheetCount = Worksheets.Count</p>
<p>&#8216;unprotect each sheet number until the sheetCount is reached<br />
For i = 1 To sheetCount<br />
    Sheets(i).Unprotect<br />
Next i</p>
<p>End Sub</p>
<p>Sub Unlocks_All()</p>
<p>&#8216; Unlocks everything, be careful using this..<br />
&#8216; You must run the UnprotectSh sub first so that all of the sheets can be selected</p>
<p>&#8216;select every cell on every sheet and substitute these sheet names with yours,<br />
&#8216;recording a macro and selecting all of the sheets is the easiest way..<br />
    Sheets(Array(&#8220;Year to Date Summary&#8221;, &#8220;January&#8221;, &#8220;February&#8221;, &#8220;March&#8221;, &#8220;April&#8221;, &#8220;May&#8221;, _<br />
    &#8220;June&#8221;, &#8220;July&#8221;, &#8220;August&#8221;, &#8220;September&#8221;, &#8220;October&#8221;, &#8220;November&#8221;, &#8220;December&#8221;)).Select<br />
    Sheets(&#8220;Year to Date Summary&#8221;).Activate<br />
    Cells.Select<br />
    Range(&#8220;A1?).Activate</p>
<p>    &#8216;unlocks the selected cells and ensure that formulas *can* be seen<br />
    Selection.Locked = False<br />
    Selection.FormulaHidden = False</p>
<p>    &#8216;select only one cell so that it&#8217;s neater, again, substitute your values<br />
    Sheets(&#8220;Year to Date Summary&#8221;).Select<br />
    Range(&#8220;A1?).Select</p>
<p>End Sub</p>
<p>Remember to lock everything down again when on Workbook_Open, I use a Locks_All and ProtectSh in that order and they&#8217;re basically the reverse of the unlock and unprotect.  Good luck!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: June</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-26150</link>
		<dc:creator>June</dc:creator>
		<pubDate>Fri, 03 Aug 2007 07:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-26150</guid>
		<description>&lt;p&gt;Release locks before close &amp; unprotect the worksheets because there are data exchange between the workbooks by VBA. The VBA can&#039;t work for protected worksheets. Please help. Thanks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Release locks before close &amp; unprotect the worksheets because there are data exchange between the workbooks by VBA. The VBA can&#8217;t work for protected worksheets. Please help. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tushar Mehta</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-26145</link>
		<dc:creator>Tushar Mehta</dc:creator>
		<pubDate>Thu, 02 Aug 2007 23:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-26145</guid>
		<description>&lt;p&gt;Responding to the original post...Might it not be easier to check if the workbook is dirty and ask the user if they want to save the WB?  Then, if the answer is yes and the WB has never been saved proceed to the GetFileSaveAs dialog box.&lt;/p&gt;
&lt;p&gt;And, no, it would not be OK -- as some klutz in some other discussion wrote s/he would do -- to simply set the WB&#039;s Saved property to True, which I imagine would mean Excel would not ask the user if the WB should be saved.  There are any number of times when I close a document expecting the program to ask me if it should be saved.&lt;/p&gt;
&lt;p&gt;Of course, this presumes that it is OK to programmatically save the file after Excel has initiated the close process.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Responding to the original post&#8230;Might it not be easier to check if the workbook is dirty and ask the user if they want to save the WB?  Then, if the answer is yes and the WB has never been saved proceed to the GetFileSaveAs dialog box.</p>
<p>And, no, it would not be OK &#8212; as some klutz in some other discussion wrote s/he would do &#8212; to simply set the WB&#8217;s Saved property to True, which I imagine would mean Excel would not ask the user if the WB should be saved.  There are any number of times when I close a document expecting the program to ask me if it should be saved.</p>
<p>Of course, this presumes that it is OK to programmatically save the file after Excel has initiated the close process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dick Kusleika</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-26138</link>
		<dc:creator>Dick Kusleika</dc:creator>
		<pubDate>Thu, 02 Aug 2007 15:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-26138</guid>
		<description>&lt;p&gt;June:  Why do you need to release the locks before close?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>June:  Why do you need to release the locks before close?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: June</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-26133</link>
		<dc:creator>June</dc:creator>
		<pubDate>Thu, 02 Aug 2007 10:57:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-26133</guid>
		<description>&lt;p&gt;Dick,&lt;/p&gt;
&lt;p&gt;For my case, some cells are locked &amp; protected during open. And I need to release the locks and protection before close the file.&lt;/p&gt;
&lt;p&gt;My issue is if the user close the worksheet but not save, how can I save my lock / protection release setup information.&lt;/p&gt;
&lt;p&gt;Please help. Thanks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Dick,</p>
<p>For my case, some cells are locked &amp; protected during open. And I need to release the locks and protection before close the file.</p>
<p>My issue is if the user close the worksheet but not save, how can I save my lock / protection release setup information.</p>
<p>Please help. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Glancy</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-21741</link>
		<dc:creator>Doug Glancy</dc:creator>
		<pubDate>Wed, 06 Dec 2006 22:44:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-21741</guid>
		<description>&lt;p&gt;(I sent this once, it&#039;s in limbo I guess, Dick please delete one if it shows up twice)&lt;/p&gt;
&lt;p&gt;Kristin,&lt;/p&gt;
&lt;p&gt;If your issue has to do with just creating and deleting the commandbar at the correct time, try just using the activate and deactivate events.  They fire when the workbook opens and closes, respectively, and deactivate avoids the problem Dick mentions above.  If, on the other hand, you need to distinguish between actions that happen at close and those that happen at deactivate, you need to do something like above.&lt;/p&gt;
&lt;p&gt;If you do have an event that you want to only happen at close, you should do like Dick suggests above.  I don&#039;t use the OnTime method, I just set the gbClosing in the Deactivate and BeforeClose events. &lt;/p&gt;
&lt;p&gt;Here&#039;s what I&#039;d do to cover both the menu creation/deletion on Activate/Deactivate and what I&#039;ll call the ReallyClose event.  This is all in the ThisWorkbook module:&lt;/p&gt;
&lt;p&gt;Public gbClosing As Boolean&lt;/p&gt;
&lt;p&gt;Private Sub Workbook_Activate()&lt;br&gt;
Dim cb As CommandBar&lt;br&gt;
Dim cbb As CommandBarButton&lt;/p&gt;
&lt;p&gt;On Error Resume Next&lt;br&gt;
    Application.CommandBars(&quot;MyBar&quot;).Delete&lt;br&gt;
On Error GoTo 0&lt;br&gt;
Set cb = Application.CommandBars.Add(&quot;MyBar&quot;)&lt;br&gt;
Set cbb = cb.Controls.Add(msoControlButton)&lt;br&gt;
cbb.Caption = &quot;Tester&quot;&lt;br&gt;
cbb.Style = msoButtonCaption&lt;br&gt;
cb.Visible = True&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Private Sub Workbook_Deactivate()&lt;br&gt;
On Error Resume Next&lt;br&gt;
Application.CommandBars(&quot;MyBar&quot;).Delete&lt;br&gt;
MsgBox &quot;Deactivate&quot;&lt;br&gt;
On Error GoTo 0&lt;br&gt;
If gbClosing Then&lt;br&gt;
    MsgBox &quot;ReallyClose&quot;&lt;br&gt;
End If&lt;br&gt;
gbClosing = False&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;Private Sub Workbook_BeforeClose(Cancel As Boolean)&lt;br&gt;
gbClosing = True&lt;br&gt;
End Sub&lt;/p&gt;
&lt;p&gt;You should know that I have bad luck in trying to improve on Dick&#039;s code - I&#039;m usually wrong :).  But try for yourself and see what you think.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>(I sent this once, it&#8217;s in limbo I guess, Dick please delete one if it shows up twice)</p>
<p>Kristin,</p>
<p>If your issue has to do with just creating and deleting the commandbar at the correct time, try just using the activate and deactivate events.  They fire when the workbook opens and closes, respectively, and deactivate avoids the problem Dick mentions above.  If, on the other hand, you need to distinguish between actions that happen at close and those that happen at deactivate, you need to do something like above.</p>
<p>If you do have an event that you want to only happen at close, you should do like Dick suggests above.  I don&#8217;t use the OnTime method, I just set the gbClosing in the Deactivate and BeforeClose events. </p>
<p>Here&#8217;s what I&#8217;d do to cover both the menu creation/deletion on Activate/Deactivate and what I&#8217;ll call the ReallyClose event.  This is all in the ThisWorkbook module:</p>
<p>Public gbClosing As Boolean</p>
<p>Private Sub Workbook_Activate()<br />
Dim cb As CommandBar<br />
Dim cbb As CommandBarButton</p>
<p>On Error Resume Next<br />
    Application.CommandBars(&#8220;MyBar&#8221;).Delete<br />
On Error GoTo 0<br />
Set cb = Application.CommandBars.Add(&#8220;MyBar&#8221;)<br />
Set cbb = cb.Controls.Add(msoControlButton)<br />
cbb.Caption = &#8220;Tester&#8221;<br />
cbb.Style = msoButtonCaption<br />
cb.Visible = True<br />
End Sub</p>
<p>Private Sub Workbook_Deactivate()<br />
On Error Resume Next<br />
Application.CommandBars(&#8220;MyBar&#8221;).Delete<br />
MsgBox &#8220;Deactivate&#8221;<br />
On Error GoTo 0<br />
If gbClosing Then<br />
    MsgBox &#8220;ReallyClose&#8221;<br />
End If<br />
gbClosing = False<br />
End Sub</p>
<p>Private Sub Workbook_BeforeClose(Cancel As Boolean)<br />
gbClosing = True<br />
End Sub</p>
<p>You should know that I have bad luck in trying to improve on Dick&#8217;s code &#8211; I&#8217;m usually wrong <img src='http://www.dailydoseofexcel.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  But try for yourself and see what you think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kristin</title>
		<link>http://www.dailydoseofexcel.com/archives/2004/06/16/beforeclose-vs-beforereallyclose/#comment-21715</link>
		<dc:creator>Kristin</dc:creator>
		<pubDate>Wed, 06 Dec 2006 13:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.dailydoseofexcel.com/?p=634#comment-21715</guid>
		<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;could anybody please help me to understand this tutorial. I don&#039;t get the part where the onTime function calls &#039;CheckIfClosed&#039; and sets the value off gbClosing to false. Does this also work without the the &#039;CheckIfClosed&#039; function? Or shouldn&#039;t the gbClosing be set to true in the function &#039;CheckIfClosed&#039; to make this work?&lt;/p&gt;
&lt;p&gt;Please help me to understand it better, I need this to solve exactly the same problem with a selfmade commandbar.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br&gt;
Kristin&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>could anybody please help me to understand this tutorial. I don&#8217;t get the part where the onTime function calls &#8216;CheckIfClosed&#8217; and sets the value off gbClosing to false. Does this also work without the the &#8216;CheckIfClosed&#8217; function? Or shouldn&#8217;t the gbClosing be set to true in the function &#8216;CheckIfClosed&#8217; to make this work?</p>
<p>Please help me to understand it better, I need this to solve exactly the same problem with a selfmade commandbar.</p>
<p>Thanks,<br />
Kristin</p>
]]></content:encoded>
	</item>
</channel>
</rss>

